This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
AW: _set_new_handler vs. set_new_handler
- From: "Lindner Bernhard" <Bernhard dot Lindner at Micronas dot com>
- To: <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 25 Aug 2005 19:09:40 +0200
- Subject: AW: _set_new_handler vs. set_new_handler
Hi!
> > Is it possible to implement such a retry-alloc-mechanism using the
GCC
> > std lib?
>
> void noMoreMemory()
> {
> free(panic_heap_memory); panic_heap_memory = 0;
> oskit::io::BSPLog::bsp_log("called noMoreMemory", 0);
> std::set_new_handler(reallyNoMoreMemory);
> }
>
> // for std::set_new_handler
> #include <new>
>
> std::set_new_handler(noMoreMemory);
>
>
> reallyNoMoreMemory is same as noMoreMemory but with more memory.
> panic_heap_memory is allocated at startup.
>
> This should work for you I think.
This isn't exactly what I want to do. This solution of course is an
improvement compared to the default out-of-memory handler (which simply
does nothing to recover the situation). But the original method I
described is much better because the user is requested using a fall back
dialog and even in the case of a very big lack of memory, the user can
continue the application by closing any number of other programs to free
enough memory.
The above solution only works if the panic memory is as big as the lack
of memory (which is not very likely because the panic memory may not be
very big if I want to prevent my application from wasting resources).
--
Regards, Bernhard