Re: Detecting 'new' operator failure?
On Fri, 5 Jun 2009 23:47:52 -0700 (PDT), Woody <ols6000@sbcglobal.net>
wrote:
With the current code, I never get to the 'catch' clause at all. Are
you saying things work differently if I specify a CException instead
of a CMemoryException? I don't see how that could be. However, I will
try it and see what happens.
No, the only change I made to your catch type was to change CException to
CException*.
Of course, prefer std::vector<char> to a raw pointer.
Not for this particular application. Memory is critical, and so is
execution speed. I don't need the overhead of the library.
Neither of those things seem like considerations for vector vs. new char[],
especially in light of the fact you're using exceptions and MFC. Vector is
preferred for exception safety reasons, and it's all around easier to work
with as a dynamic array type. I can think of a couple of very minor things
that could make certain infrequent operations slower, but I have a hard
time imagining them having any significance in real programs.
I see that set_new_handler looks like what I want.
It's a rather blunt tool, and I wouldn't use it with a library like MFC
that expects a failed new to throw CMemoryException*.
--
Doug Harrison
Visual C++ MVP