Re: bad_alloc
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Mon, 7 Jan 2008 09:04:03 -0600
<George George> wrote in message news:2008155957george4academic@xxxxxxxxxxxx
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?
Of course.
new will fail whenever (free contiguous memory < requested allocation size)
This inequality can be satisfied just as easily by a ridiculous righthand
side as by a small lefthand side.
Note however that you shouldn't rely on this mechanism to detect invalid
input. You should not pass a user-supplied value to new.
thanks in advance,
George
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
.
- References:
- bad_alloc
- From: George George
- bad_alloc
- Prev by Date: Re: How to troubleshoot bugchecks on my own?
- Next by Date: Re: memory leak in the code?
- Previous by thread: bad_alloc
- Next by thread: memory leak in the code?
- Index(es):
Relevant Pages
|
Loading