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

Re: bad_alloc by Bo

Bo
Sat Jan 05 07:00:49 CST 2008

George 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?
::

A bad_alloc tells you that a memory allocation failed.

Processing input *might* involve some internal memory allocation, so
it could cause a bad_alloc. Generally it does not.



Bo Persson



Re: bad_alloc by George

George
Sat Jan 05 07:27:00 CST 2008

So Bo,


In your experience, invalid input value does not cause bad_alloc? So, the
only case you met with is out of memory?


regards,
George

"Bo Persson" wrote:

> George 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?
> ::
>
> A bad_alloc tells you that a memory allocation failed.
>
> Processing input *might* involve some internal memory allocation, so
> it could cause a bad_alloc. Generally it does not.
>
>
>
> Bo Persson
>
>
>

Re: bad_alloc by Alexander

Alexander
Mon Jan 07 11:12:25 CST 2008

I suspect Bo misunderstood you by thinking of user input.
Note there's no invalid value for the size in operator new.
Thus if you specify an unreasonably large value the allocator
will honestly attempt to allocate that large chunk of memory
and fail - because there's not enough memory.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"George" <George@discussions.microsoft.com> wrote in message
news:67565296-364C-4647-AD4C-22B5BBE85643@microsoft.com...
> So Bo,
>
>
> In your experience, invalid input value does not cause bad_alloc? So, the
> only case you met with is out of memory?
>
>
> regards,
> George
>
> "Bo Persson" wrote:
>
>> George 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?
>> ::
>>
>> A bad_alloc tells you that a memory allocation failed.
>>
>> Processing input *might* involve some internal memory allocation, so
>> it could cause a bad_alloc. Generally it does not.
>>
>>
>>
>> Bo Persson
>>
>>
>>



Re: bad_alloc by George

George
Mon Jan 07 23:38:01 CST 2008

The same as negative value, Alexander!


regards,
George

"Alexander Nickolov" wrote:

> I suspect Bo misunderstood you by thinking of user input.
> Note there's no invalid value for the size in operator new.
> Thus if you specify an unreasonably large value the allocator
> will honestly attempt to allocate that large chunk of memory
> and fail - because there's not enough memory.
>
> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD
> email: agnickolov@mvps.org
> MVP VC FAQ: http://vcfaq.mvps.org
> =====================================
>
> "George" <George@discussions.microsoft.com> wrote in message
> news:67565296-364C-4647-AD4C-22B5BBE85643@microsoft.com...
> > So Bo,
> >
> >
> > In your experience, invalid input value does not cause bad_alloc? So, the
> > only case you met with is out of memory?
> >
> >
> > regards,
> > George
> >
> > "Bo Persson" wrote:
> >
> >> George 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?
> >> ::
> >>
> >> A bad_alloc tells you that a memory allocation failed.
> >>
> >> Processing input *might* involve some internal memory allocation, so
> >> it could cause a bad_alloc. Generally it does not.
> >>
> >>
> >>
> >> Bo Persson
> >>
> >>
> >>
>
>
>

Re: bad_alloc by Igor

Igor
Tue Jan 08 08:22:24 CST 2008

"George" <George@discussions.microsoft.com> wrote in message
news:3F1F7702-F848-4009-B9E7-17349344C771@microsoft.com
>> I suspect Bo misunderstood you by thinking of user input.
>> Note there's no invalid value for the size in operator new.
>> Thus if you specify an unreasonably large value the allocator
>> will honestly attempt to allocate that large chunk of memory
>> and fail - because there's not enough memory.
>
> The same as negative value, Alexander!

What negative value? operator new() takes size_t as a parameter, which
is an unsigned integer type.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: bad_alloc by George

George
Tue Jan 08 08:33:00 CST 2008

Sorry, Igor!


My mistake. I think if we pass negative value, it will be converted to
unsigned value -- a very large one -- which exceeds the size of available
memory, then bad_alloc will happen. Right?


regards,
George

"Igor Tandetnik" wrote:

> "George" <George@discussions.microsoft.com> wrote in message
> news:3F1F7702-F848-4009-B9E7-17349344C771@microsoft.com
> >> I suspect Bo misunderstood you by thinking of user input.
> >> Note there's no invalid value for the size in operator new.
> >> Thus if you specify an unreasonably large value the allocator
> >> will honestly attempt to allocate that large chunk of memory
> >> and fail - because there's not enough memory.
> >
> > The same as negative value, Alexander!
>
> What negative value? operator new() takes size_t as a parameter, which
> is an unsigned integer type.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>

Re: bad_alloc by Igor

Igor
Tue Jan 08 13:48:45 CST 2008

George <George@discussions.microsoft.com> wrote:
> My mistake. I think if we pass negative value, it will be converted to
> unsigned value -- a very large one -- which exceeds the size of
> available memory, then bad_alloc will happen. Right?

Right.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: bad_alloc by George

George
Tue Jan 08 21:37:02 CST 2008

Thanks for your confirmation, Igor.


My question is answered.


regards,
George

"Igor Tandetnik" wrote:

> George <George@discussions.microsoft.com> wrote:
> > My mistake. I think if we pass negative value, it will be converted to
> > unsigned value -- a very large one -- which exceeds the size of
> > available memory, then bad_alloc will happen. Right?
>
> Right.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>
>