[olpc-software] graceful handling of out-of-memory conditions

Alan Cox alan at redhat.com
Tue Mar 28 11:47:51 UTC 2006


On Tue, Mar 28, 2006 at 09:33:37PM +1000, msevior at physics.unimelb.edu.au wrote:
> Instead we have code like:
> 
> SomeClass * p = new SomeClass(...);
> p->SomeMethod(...);
> 
> The original authors of AbiWord put in such checks but in practice we've
> never seen AbiWord fail this way so they have fallen out of favour.

std:set_new_handler(out_of_memory_func);

If I remember rightly C++ new failure throws "bad_alloc" as an exception
anyway nowdays rather than return NULL. (and no idea what occurs in this case
if you build with exceptions disabled). I guess the bad_alloc is closer to
what you need than a signal as its synchronous

> OK Once again my own ignorance shows. How can I find out what these are?

For C they are defined in the C language and POSIX/SuS specifications. Not
sure how it works for C++. See "info libc signal" and the Nonreentrancy node
for more info.

Alan




More information about the olpc-software mailing list