Re: bad_alloc




<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


.



Relevant Pages

  • Re: Address Verification
    ... Apparently, this is the reason why no one,apart from Memory Manager ... not loaded in RAM (i.e P bit of its corresponding entry in the page ... no chance to return TRUE if the target address is invalid in the ... ), but this throws exceptions ...
    (microsoft.public.development.device.drivers)
  • Re: Problems with MapCallerPtr (WinCE 5.0)
    ... full access privileges :-( ... debugging I tried to go into the memory location returned by the ... invalid. ... But if the location is on heap (dynamically ...
    (microsoft.public.windowsce.platbuilder)
  • Re: bad_alloc
    ... Note there's no invalid value for the size in operator new. ... and fail - because there's not enough memory. ... :: any other situations when we will get bad_alloc exceptions? ... A bad_alloc tells you that a memory allocation failed. ...
    (microsoft.public.vc.language)
  • RE: aligned to the natural size? invalid address?
    ... both null exceptions and invalid address. ... Invalid addresses are memory ... when the CLR encounters a null. ...
    (microsoft.public.dotnet.framework.clr)
  • bad_alloc
    ... I am wondering except when there is no memory on heap, are there any other situations when we will get bad_alloc exceptions? ... invalid input of the size will cause exception? ...
    (microsoft.public.win32.programmer.kernel)

Loading