Re: Dynamic Allocation Problem.....

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



Hallo Muthukumar!

Note that this is a german newsgroup.

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?

Usually malloc fails only if there is no memeory left to allocate.
But malloc can also fail when the heap gets corrupted. But in a debug version you will see some debug output in this case.


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.

You are overwriting memory blocks so free fail and asserts because the pointer structure in the heap is no longer valid.


You can use _heapchk at any point in your program to validate the heap.

--
Martin Richter [MVP] WWJD
"In C we had to code our own bugs. In C++ we can inherit them."
FAQ : http://www.mpdvc.de
Samples: http://www.codeguru.com http://www.codeproject.com
.



Relevant Pages

  • Re: This calculation is just wrong / computer cant count!
    ... and I replied "new or malloc". ... It is not the fastest way to allocate memory". ... think that VirtualAlloc is faster than malloc has some serious issues, ... then there is no error only a precision limit. ...
    (microsoft.public.vc.mfc)
  • Re: difference between malloc and calloc?
    ... malloc(), and that's the opportunity for a tiny bit of sanity- checking. ... Here are two ways you might try to allocate memory to ... calloc() almost never. ... There is no special dispensation for overflow of nmemb * size; there is just the requirement for a NULL returned value. ...
    (comp.lang.c)
  • Re: difference between malloc and calloc?
    ... malloc(), and that's the opportunity for a tiny bit of sanity- checking. ... Here are two ways you might try to allocate memory to ... calloc() almost never. ... void *p = malloc; ...
    (comp.lang.c)
  • Dynamic Allocation Issues...
    ... malloc() to allocate memory for the Pointer variables. ... and hence it leads to Unhandled Exception. ...
    (microsoft.public.vc.ide_general)
  • Dynamic Allocation Problem.....
    ... malloc() to allocate memory for the Pointer variables. ... and hence it leads to Unhandled Exception. ...
    (microsoft.public.win32.programmer.messaging)