Re: Dynamic Allocation Problem.....
- From: "Martin Richter [MVP]" <martin.richter@xxxxxxxx>
- Date: Fri, 27 May 2005 08:03:59 +0200
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 .
- Prev by Date: Re: Arrays zurückgeben
- Next by Date: Re: Arrays zurückgeben
- Previous by thread: debug break bei Speicherzugriff?
- Next by thread: G.711 Kompression - Quellcode gesucht
- Index(es):
Relevant Pages
|