AW: _set_new_handler vs. set_new_handler

Lindner Bernhard Bernhard.Lindner@Micronas.com
Fri Aug 26 08:52:00 GMT 2005


Hi!

> it doesn't waste memory, it frees preallocated memory at certain
steps,
> and the user of "new" will get the memory it needs after the
> preallocated memory is freed up in the handler. I use it in an
embedded
> environment, where I can't "pop up" a window, but log the event an
track
> unexpected memory usage on the device.

There are two issues I don't understand: 
You say this solution doesn't waste memory. But in fact the preallocated
memory is lost for the rest of the system and under normal conditions
the application will not use that panic memory at all. I think this
could be called "wasting" the memory, isn't it?
Additionally I just noticed that I probably don't understand the overall
mechanism. If you call "new" and this operation fails due the lack of
memory, then the given new-handler is called. In this new-handler you
are freeing a bunch of panic memory. The successional calls to new then
will probably work fine, since free memory is available. But what's
about the original new-call, which caused the handler to be executed? It
will still fail and return NULL, won't it? Or is there any kind of
retry-machanism I don't know about? The C runtime will not retry to
allocate the memory after a call to the new-handler, will it?

> as a general rule, memory should not exeed; and if so, we log it
instead
> of abort()

Of course.

> decide which "application" to kill on the event is not easy without
> user intervention.

That's why I would like to ask the user.

-- 
Regards, Bernhard




More information about the Libstdc++ mailing list