what I am doing is create a header file including:
#include "stdafx.h"
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
I inteneded to put it in a header file like common.h so every other header files including this one could also have memory leak detection. However one problem is the compiler will give me errors about redefination of new operator, I will plaste the errors information in the end of this post due to it is quite long. I can solve the problem by putting #include "LumPyDetectMemoryLeak.h" in the cpp files instead of header files, which seems really awkward inefficient. Any one have any idea how to solve this problem in another way? Plus even though I include LumPyDetectMemoryLeak.h in all of my cpp files, In the end there are still some outputs that do not show where the memory leaks are. So I am wondering if I need to define the same thing in inline files or some other places?
c:\users\jerry\desktop\lumpy\lumpy\test.cpp(23) : {136} client block at 0x002C7848, subtype 0, 192 bytes long.
Data: < , > 94 09 EB 00 00 00 00 00 18 18 2C 00 CD CD CD CD
c:\users\jerry\desktop\lumpy\lumpy\lumpystring.cpp(17) : {135} client block at 0x002C17D8, subtype 0, 1 bytes long.
Data: < > 00
c:\users\jerry\desktop\lumpy\lumpy\test.cpp(21) : {134} client block at 0x002C7508, subtype 0, 768 bytes long.
Data: <8 , > 38 FE EA 00 00 00 00 00 D8 17 2C 00 CD CD CD CD
{125} normal block at 0x002C1778, 32 bytes long.
Data: < > A4 18 EB 00 CD CD CD CD CD CD CD CD CD CD CD CD
{124} normal block at 0x002C1718, 32 bytes long.
j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2365: 'operator new' : redefinition; previous definition was 'function'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2491: 'new' : definition of dllimport data not allowed
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2078: too many initializers
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2440: 'initializing' : cannot convert from 'int' to 'void *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2143: syntax error : missing ';' before '('
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(32) : error C2226: syntax error : unexpected type 'size_t'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(33) : error C2059: syntax error : ')'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : warning C4229: anachronism used : modifiers on data are ignored
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2365: 'operator new' : redefinition; previous definition was 'function'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2491: 'new' : definition of dllimport data not allowed
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2078: too many initializers
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2440: 'initializing' : cannot convert from 'int' to 'void *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2143: syntax error : missing ';' before '['
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : error C3409: empty attribute block is not allowed
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xdebug(36) : error C2226: syntax error : unexpected type 'size_t'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(143) : error C2059: syntax error : 'constant'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(144) : error C2091: function returns function
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(144) : error C2802: static member 'operator new' has no formal parameters
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(144) : error C2333: 'std::locale::facet::operator new' : error in function declaration; skipping function body
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(149) : error C2059: syntax error : 'constant'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(151) : error C2091: function returns function
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(151) : error C2556: 'void *(__cdecl *std::locale::facet::operator new(void))(size_t,const std::_DebugHeapTag_t &,char *,int)' : overloaded function differs only by return type from 'void *(__cdecl *std::locale::facet::operator new(void))(size_t)'
1> j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(143) : see declaration of 'std::locale::facet::operator new'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(152) : error C2059: syntax error : 'return'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(152) : error C2238: unexpected token(s) preceding ';'
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(155) : error C2628: 'std::locale::facet' followed by 'void' is illegal (did you forget a ';'?)
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(157) : error C2487: 'delete' : member of dll interface class may not be declared with dll interface
1>j:\program files (x86)\microsoft visual studio 9.0\vc\include\xlocale(157) : error C2817: return type for 'operator delete' must be 'void'