November 20th, 2012, 01:05 PM
Re: Windows CE (STL + std::bad_alloc + CMemoryException, ...)
The CMemoryException is an MFC class. Wherever you got this information from, it is pertaining strictly to MFC. There is no MFC in the original code you posted, except for CMemoryException, which is why it's strange - the code has no other MFC in it whatsoever, not even including any MFC header files. So how could this code have even compiled correctly?
Originally Posted by Erakis
That's why it's important to post all your code -- the code you posted (minus the CMemoryException object which has no way of being compiled successfully) was a vanilla C++ program, due to that the rules of "vanilla" ANSI C++ are supposed to be put into action. Those rules include that "new" must throw a std::bad_alloc exception on failure. If your code is really an MFC program, then the answers you get would have been different, since MFC has overloaded the new operator to return a NULL.
No. Using placement-new allocates no memory -- what if the memory allocation is really done by malloc(), calloc(), etc. or the library is smart enough to use an array for smaller objects and only allocate using one of those functions when the number of objects become larger? Those are not hooked into the set_new_handler() mechanism.
Even if the allocation was made on a PLACEMENT NEW, as the stl container would swell, he should allocate memory somewhere for his placement area. So if this operation fails, then my new_handler should be called. Not ?
The bottom line is this -- the only thing that is guaranteed is that the calls to "new" that you make explicitly are tracked. Otherwise, you're relying on behaviour that may change or may be different, depending on how the library is implemented, compiler options chosen, etc. Look at the Visual C++ 2008 version -- there is a placement new there, so your assumptions about what gets allocated would have been false.
Last edited by Paul McKenzie; November 20th, 2012 at 01:11 PM.
Tags for this Thread
Click Here to Expand Forum to Full Width