I am currently developing a simple memory tracker to trace memory leaks. I am using
this article for it.
The used code I have so far is like this:
#include <malloc.h>
#ifdef _DEBUG
// Overloaded new operator, taking as parameters the Size of the block to be
// allocated, the filename and linenumber from where it''s called
inline void * __cdecl operator new(unsigned int Size, const char *szFile, int Line)
{
void *ptr = (void *)malloc(Size);
AddTrack((DWORD)ptr, Size, szFile, Line);
return (ptr);
};
// Overloaded delete operator
inline void __cdecl operator delete(void *p)
{
RemoveTrack((DWORD)p);
free(p);
};
#endif
#ifdef _DEBUG
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#define new DEBUG_NEW
However, this gives me an compiler warning, as shown below:
F:\Projects\CWindow\main.cpp(55) : warning C4291: ''void *__cdecl operator new(unsigned int,const char *,int)'' : no matching operator delete found; memory will not be freed if initialization throws an exception
f:\projects\cwindow\memmanager.h(6) : see declaration of ''new''
I am confused, what is the problem?
Toolmaker
-Earth is 98% full. Please delete anybody you can.