bad_alloc



 DEVELOP > c-Plus-Plus > bad_alloc

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "George2"
Date: 05 Jan 2008 04:09:20 AM
Object: bad_alloc
Hello everyone,
I am wondering except when there is no memory on heap, are there any
other situations when we will get bad_alloc exceptions? For example,
invalid input of the size (e.g. very huge number or zero or negative
number) will cause exception?
thanks in advance,
George
.

User: "Ian Collins"

Title: Re: bad_alloc 05 Jan 2008 04:16:53 AM
George2 wrote:

Hello everyone,


I am wondering except when there is no memory on heap, are there any
other situations when we will get bad_alloc exceptions? For example,
invalid input of the size (e.g. very huge number or zero or negative
number) will cause exception?

Doesn't that describe exhausting the heap?
--
Ian Collins.
.

User: ""

Title: Re: bad_alloc 05 Jan 2008 06:25:09 AM
George2 wrote:

Hello everyone,


I am wondering except when there is no memory on heap, are there any
other situations when we will get bad_alloc exceptions? For example,
invalid input of the size (e.g. very huge number or zero or negative
number) will cause exception?

As far as the standard is concerned, new could throw bad_alloc randomly on
Wednesdays: the standard only says that bad_alloc indicates that the new
handler did not succeed in allocating memory, it does not specify how hard
the handler has to try. From a quality of implementation point of view,
however, you will probably not find such an implementation.
Best
Kai-Uwe Bux
.
User: "James Kanze"

Title: Re: bad_alloc 05 Jan 2008 11:59:22 AM
On Jan 5, 1:25 pm,
wrote:

George2 wrote:

I am wondering except when there is no memory on heap, are
there any other situations when we will get bad_alloc
exceptions? For example, invalid input of the size (e.g.
very huge number or zero or negative number) will cause
exception?

As far as the standard is concerned, new could throw bad_alloc
randomly on Wednesdays: the standard only says that bad_alloc
indicates that the new handler did not succeed in allocating
memory, it does not specify how hard the handler has to try.
From a quality of implementation point of view, however, you
will probably not find such an implementation.

During testing, I use my own custom operator new, precisely
because it has an option which allows the test harness to
request a bad_alloc after n allocations. Unless you have
actually triggers a bad_alloc, you haven't tested any code using
dynamic allocation (and I'd argue that it is morally
irresponsible to release such code). From a quality of
implementation point of view, I'd consider such an option in the
library implementation a big plus.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.
User: "kwikius"

Title: Re: bad_alloc 06 Jan 2008 02:52:49 AM
On Jan 5, 5:59=A0pm, James Kanze <james.ka...@gmail.com> wrote:

On Jan 5, 1:25 pm,

wrote:

George2 wrote:

I am wondering except when there is no memory on heap, are
there any other situations when we will get bad_alloc
exceptions? For example, invalid input of the size (e.g.
very huge number or zero or negative number) will cause
exception?

As far as the standard is concerned, new could throw bad_alloc
randomly on Wednesdays: the standard only says that bad_alloc
indicates that the new handler did not succeed in allocating
memory, it does not specify how hard the handler has to try.
From a quality of implementation point of view, however, you
will probably not find such an implementation.


During testing, I use my own custom operator new, precisely
because it has an option which allows the test harness to
request a bad_alloc after n allocations.

It occurs to me that an ideal test implementation should also provide
an option to make sure you really are out of memory then throw
bad_alloc, ideally using various mechanisms.
regards
Andy Little
.



User: "Rahul"

Title: Re: bad_alloc 05 Jan 2008 04:20:51 AM
On Jan 5, 3:09 pm, George2 <george4acade...@yahoo.com> wrote:

Hello everyone,

I am wondering except when there is no memory on heap, are there any
other situations when we will get bad_alloc exceptions? For example,
invalid input of the size (e.g. very huge number or zero or negative
number) will cause exception?

thanks in advance,
George

when the user defined operator new throws bad_alloc on purpose...
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER