[Exceptional C++ Style] Item 22: To new, Perchance to throw, Part 2: Pragmatic Issues in Memory Management

Terje Slettebø tslettebo at broadpark.no
Fri Jan 21 05:00:09 EST 2005


>From: "Jez Higgins" <jez at jezuk.co.uk>

> This leads us to moral #1 : Avoid nothrow new
> ...
> Moral #2 : There's often no point in checking for new failure anyway.
>
> Let's temper our saintly impulses with a practicality.  Many systems
> allocate memory on an optimistic basis, and don't commit it until the
> memory is actually used.  Memory allocation on such systems (eg Linux)
> always succeeds, although, rather unfortunately, any subsequent memory
> write may fail.  It's not conformant, but it's life.
>
> ---
>
> I've never seen a program that attempted to recover from new
> failing, nor one that used the nothrow form of new.

Some systems may compile with exceptions disabled, and therefore can only
safely use the nothrow version. No, that's not conformant, but, er, that's
life, too.

Regards,

Terje




More information about the Effective-cpp mailing list