[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3439.0. "Question of behaviour of new" by TAEC::FLAUW (Marc Flauw, TeMIP Technical Office, VBO) Mon Feb 10 1997 04:53

Hello,

I have a question related to the behaviour of the new operator when the
memory allocation fails:

In the ANSI C++ Working Paper (Nov 96), I read that the new operators are
defined as throwing the bad_alloc exception:

   void* operator new(std::size_t) throw(std::bad_alloc);
   void* operator new[](std::size_t) throw(std::bad_alloc);

and in the section describing storage duration (3.7.3.1 bullet 3):
"
3 An allocation function that fails to allocate storage can  invoke  the
  currently  installed  new_handler  (_lib.new.handler_).  [Note: A pro-
  gram-supplied allocation function can obtain the address of  the  cur-
  rently   installed  new_handler  using  the  set_new_handler function
  (_lib.set.new.handler_).   ]  If   a   nothrow   allocation function
  (_lib.support.dynamic_)  fails  to allocate storage, it shall return a
  null pointer.  Any other allocation function that  fails  to allocate
  storage  shall only indicate failure by throwing an exception of class
  std::bad_alloc   (_lib.bad.alloc_)   or   a   class derived    from
  std::bad_alloc.
"

Would this mean that if we use the standard new operator, a new will never
return a null pointer and we can remove from our code tests such as:

    p = new T(...)
    if (p == NULL)
      {
       // throw my insuf memory exception
      }

Is this behaviour already available and if not, in which version of the
compiler is it planned, V5.6, V6.0 ?

Thanks and regards,

Marc. 		    
T.RTitleUserPersonal
Name
DateLines
3439.1a little waitHNDYMN::MCCARTHYA Quinn Martin ProductionMon Feb 10 1997 05:5613
>>Would this mean that if we use the standard new operator, a new will never
>>return a null pointer and we can remove from our code tests such as:

	[ snip ] 

Yes.

>>Is this behaviour already available and if not, in which version of the
>>compiler is it planned, V5.6, V6.0 ?

Not yet.  V6.0

Brian J.
3439.2ThanksTAEC::FLAUWMarc Flauw, TeMIP Technical Office, VBOMon Feb 10 1997 06:025
Thanks, Brian.

That was quick.

/marc.