[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: About memory allocation failures....
From:       "Schmidt, John" <John_Schmidt () compuware ! com>
Date:       2002-03-23 2:04:03
[Download RAW message or body]

On Friday 22 March 2002 22:51, Laurent, Guillaume wrote:
> It's not wrong, it's true for all practical purposes. Here's the deal :
>
> The Standard used to say : new returns 0 on failure. That was amended
years 
> ago (don't know the exact date - before 97 since that was when the
standard 
> was voted). Now new throws bad_alloc by default, but you can set up your
own 
> handler, which indeed may not throw.

The IBM VisualAge C++ compiler does NOT throw bad_alloc, it returns NULL by
default. Same with the MS VisualC++ 6.0 compiler.  Haven't tried it using
the 
Sun or HPUX compilers yet.  The "standard" as set by Bjarne indicates
bad_alloc
is the default, but that does not seem to be the case for all compilers.

> So yes, if you really like splitting hairs, "new never returns null" is 
> wrong. However, setting up your own handler is a fairly advanced technique

> which I doubt many compilers support, and even if both conditions are 
> satisfied, then you still pretty much want your handler to throw anyway 
> because that's the sanest thing to do. Of course there certainly are 
> exceptions.

Setting up your own handler (or using nothrow) IS splitting hairs, but
saying 
it's an advanced technique is like saying coding a destructor for 
pthread_key_create() is advanced?  As far as supporting set_new_handler, VAC

C++, Sun, and HPUX support it for we have common code used on those
platforms, 
and it's in the gcc <new>.
  
> But as far as the audience of this list is concerned, 'new' never returns 
> null, checking for memory allocation failure is futile except perhaps when

> you're allocating a really large buffer, and further inquiries on the
subject 
> should be carried to a suitable place like comp.lang.c++.

I guess if the only compiler of interest for those on this list is gcc, new
by default never returns NULL.  I'd just as soon let the audience (sorry
folks!) 
decide for themselves wrt the nuances of various compilers... let's just
call it
good and say we agree to disagree on "default" and "never."  Whether or
not memory allocation checks are futile or not I will address from Kuba's
post on the subject... I ran some tests in KDE so it should be relevant. 


regards,
John Schmidt
ServerVantage Development
Compuware Corporation
http://www.compuware.com/products/vantage
john.schmidt@compuware.com
 



The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.  

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic