Re: Can't get debug heap working



<jmagnuss@xxxxxxxxx> wrote:
These are the CObject operator new declarations,

--- CUT ---
#if defined(_DEBUG) && !defined(_AFX_NO_DEBUG_CRT)
// for file name/line number tracking using DEBUG_NEW
void* PASCAL operator new(size_t nSize, LPCSTR lpszFileName, int
nLine);
#if _MSC_VER >= 1200
void PASCAL operator delete(void *p, LPCSTR lpszFileName, int nLine);
#endif
#endif
--- CUT ---

I'm not really sure why my

#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)

is conflicting with these, and I have confirmed that _DEBUG is defined
just before the allocation I describe in my previous post.


Probably using the same name ("new") in your macro confuses preprocessor somehow. I always give different names:

// in .H file
#if defined(_DEBUG)
# define DEBUG_NEW new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
# define DEBUG_NEW
#endif // _DEBUG

// in .CPP files
#if defined(_DEBUG)
# define new DEBUG_NEW
#endif // _DEBUG

However, if you use MFC, then you don't need to do anything, since MFC already has all necessary defines in order to track `CObject' based objects.

Alex

.



Relevant Pages