Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #4821

Re: Customize operator new / delete

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Customize operator new / delete
Date 2011-05-09 10:45 +1200
Message-ID <92okogF82qU4@mid.individual.net> (permalink)
References <e557f572-1a34-4a96-aad9-ffd1241a71be@c41g2000yqm.googlegroups.com> <78a4d447-9756-4dbc-ac6d-3513dbcd5031@l6g2000vbn.googlegroups.com> <4dc6cd28$0$38644$4fafbaef@reader1.news.tin.it> <99af04ae-e877-446c-9e88-16c093d047a7@x10g2000yqj.googlegroups.com>

Show all headers | View raw


On 05/ 9/11 10:35 AM, Nephi Immortal wrote:
> On May 8, 12:05 pm, "io_x"<a...@b.c.invalid>  wrote:
>> "James Kanze"<james.ka...@gmail.com>  ha scritto nel messaggionews:78a4d447-9756-4dbc-ac6d-3513dbcd5031@l6g2000vbn.googlegroups.com...
>>
>>> The operator new do not meet the requirements set down in the
>>> standard, particularly the post-condition that the returned
>>> pointer is never null.  You have to do something like:
>>
>>>     void operator new( size_t size )
>>>     {
>>>         void* result = malloc( size );
>>>         if ( result == NULL ) {
>>>             throw std::bad_alloc();
>>
>> for me better what does malloc(); it return 0, so each function know
>> the path they have to follow: the error path; each function for its
>> responsability.
>
> 	You are correct to say this way.  I don’t need to use neither throw()
> nor exception.  The allocation failure will be reported to the error
> handler and malloc sets errno to ENOMEM if a memory allocation fails.
> 	The allocation failure is tested at startup before the program begins
> to run until it ends prior deallocation memory.  If error is reported,
> then the program will be terminated immediately.

If you want a no-throw allocation, use the alternative standard form:

  operator new(std::size_t, const std::nothrow_t&);

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Customize operator new / delete Nephi Immortal <immortalnephi@gmail.com> - 2011-05-07 19:11 -0700
  Re: Customize operator new / delete Ian Collins <ian-news@hotmail.com> - 2011-05-08 15:05 +1200
  Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-08 07:38 -0700
    Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-08 19:05 +0200
      Re: Customize operator new / delete Nephi Immortal <immortalnephi@gmail.com> - 2011-05-08 15:35 -0700
        Re: Customize operator new / delete Ian Collins <ian-news@hotmail.com> - 2011-05-09 10:45 +1200
      Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-10 13:25 -0700
        Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-11 09:31 +0200
          Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-11 09:56 +0200
            Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-15 06:14 -0700
              Re: Customize operator new / delete Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-15 23:54 -0700
                Re: Customize operator new / delete Ian Collins <ian-news@hotmail.com> - 2011-05-16 19:43 +1200
                Re: Customize operator new / delete Nobody <nobody@nowhere.com> - 2011-05-16 12:53 +0100
              Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-18 17:32 +0200
                Re: Customize operator new / delete Pete Becker <pete@versatilecoding.com> - 2011-05-18 12:38 -0400
          Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-15 06:12 -0700
  Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-08 18:44 +0200
    Re: Customize operator new / delete Nephi Immortal <immortalnephi@gmail.com> - 2011-05-08 15:43 -0700
      Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-09 08:47 +0200
        Re: Customize operator new / delete Leigh Johnston <leigh@i42.co.uk> - 2011-05-09 12:58 +0100
          Re: Customize operator new / delete "io_x" <a@b.c.invalid> - 2011-05-10 08:15 +0200
            Re: Customize operator new / delete Leigh Johnston <leigh@i42.co.uk> - 2011-05-10 12:39 +0100
        Re: Customize operator new / delete James Kanze <james.kanze@gmail.com> - 2011-05-10 13:29 -0700

csiph-web