I had problems with mem leaks in the past (caused by a compiler error) in applications with landmarks of around 256 KB, so I had to check this somehow. After some struggle, I created a table of all the selected pointers, their sizes and some functions, in order to keep it updated. the result is the following:
File: mmap.h
//--------------------------------------------------------------------------- //--- Memory map system ver: 2.03 ------------------------------------------- //--------------------------------------------------------------------------- #ifndef _mmap_h #define _mmap_h //--------------------------------------------------------------------------- #define _mmap_aprox //--------------------------------------------------------------------------- /* new
Now in your code just do the following:
// edit the safe big enough number of pointers to use for your application in begin of the mmap.h _mmap_entries=512*1024; // before any delete/delete[] of pointer ptr add this: #ifdef _mmap_h if (ptr!=NULL) mmap_del('info',ptr); #endif if (ptr!=NULL) delete[] ptr; // after any new of pointer ptr of size siz [byte] add this: ptr=new BYTE[siz];
So, if you include mmap.h as the first enable !!!
- place breakpoint inside function void mmap_err (const char * msg, DWORD ptr)
- launch the application
- If any distribution error occurs, it will be interrupted before the exception so that you can see the info and kind off error, and you can also execute the code where the error occurs.
I am a user of BBS2006 Turbo C ++, so if I forgot some VCL materials, just convert it to MSVC ++ or comment and I will do it, but I donโt see anything that can cause problems.
PS. I found out that a fatal error occurred for my compiler:
- delete pointer more than once
- have structures without a proper constructor / destructor
in both cases, no exception is thrown, but the memory manager is subsequently corrupted, so it throws exceptions incorrectly.
The correct constructors / destructors for my compiler
for all structures and classes that will be dynamically distributed or any of their components
like this:
class/struct T { public: T() {} T(T& a) { *this=a; } ~T() {} T* operator = (const T *a) { *this=*a; return this; }
Spektre
source share