Re: Dynamic Allocation Problem...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The only legitimate failure from malloc() is a NULL pointer, and,
this happens when your process is out of memory.

In all other cases, your application must have corrupted the internal state
of the heap, and your code enters the reign of the undefined behavior.

Please compiler your application in release mode, and run it under
debugger after having enabled full page heap.
c:\debuggers>gflags -p /enable InDevelopmentApp.exe /full
c:\debuggers>start cdb -g -G InDevelopmentApp.exe
The heap instrumentation activated by gflags.exe is likely to put you
very close to the place where the corruption has happened.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Muthukumar" <muthu@xxxxxxxxxxxxxx> wrote in message
news:eJMnB7dYFHA.3712@xxxxxxxxxxxxxxxxxxxxxxx
> Dear Pals,
>
> Query 1:
>
> In my Win32 console application using Microsoft C compiler, I am using
> malloc() to allocate memory for the Pointer variables. These allocations
are
> working very fine, but sometimes malloc() failed to allocate memory and
> gives Unhandled Exception error. Pointer variable has no allocated memory
> and hence it leads to Unhandled Exception.
>
> Could you please tell me in which cases malloc get fails to allocate
memory?
> How to resolve this issue as a permanent?
>
> Query 2:
> During the deallocation time using the free() , I am getting the
"Debug
> Assertion failed" error in some cases. What might be the reason for
getting
> this Error? Could you please give the better solution.
>
> Earliest replies are very much appreciated.
>
> Regards,
> Shahul.
>
>


.



Relevant Pages

  • Re: sizeof(ptr) = ?
    ... The value returned by malloc() is of type 'void*', ... The memory is typeless until an object has been written ... Since 'void' is defined to be an incomplete ... an lvalue of a complete type, there must be a pointer conversion ...
    (comp.lang.c)
  • Re: Checking validity of a file pointer
    ... because the pointer looks valid. ... detected (preferably by having fclose return an error indication ... if the buffer of the file is returned from the malloc() function, ... with memory returned from mallocfunction in that buff ...
    (comp.lang.c)
  • Re: memory allocation wrapper
    ... I've written a wrapper for malloc and friends. ... The reason for doing writing this so that newbies ... How do I know how much memory a pointer points to? ...
    (comp.lang.c)
  • Re: 2D array of structures
    ... Don't cast the return value of malloc(), ... you allocate here memory for 7 such structures. ... a pointer to the start of this memory, which is of type 'STRUCTURE *' ...
    (comp.lang.c)
  • Re: malloc does not return null when out of memory
    ... >> malloc() when the overcommitted memory is touched, ... >> touched it and there's no actual memory there. ... This patch does ... > 1) mallocreturning a pointer, and then sometime later the program dies ...
    (freebsd-stable)