InfoVis 2013  1.0
Information Visualisation project - "Mapping Text with Phrase Nets"
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MemoryLeakTracker.h
Go to the documentation of this file.
1 #ifndef MEMORY_LEAK_TRACKER_H
2 #define MEMORY_LEAK_TRACKER_H
3 
4 void InitMemoryTracker();
5 
6 #ifdef _DEBUG
7  #define USE_MEMORY_TRACKING
8 #endif
9 
10 #ifdef USE_MEMORY_TRACKING
11  #include <crtdbg.h>
12  #include <windows.h>
13 
14  #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
15  #define new DEBUG_CLIENTBLOCK
16 
17  extern _CrtMemState mem_state;
18 
19  #define SET_CRT_DEBUG_FIELD(a) \
20  _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
21 
22  inline void DebugDumpMemory()
23  {
24  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
25  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
26  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
27  }
28 
29  inline void InitMemoryTracker()
30  {
31  SET_CRT_DEBUG_FIELD(_CRTDBG_LEAK_CHECK_DF);
32 
33  _CrtMemCheckpoint(&mem_state);
34 
35  #ifdef _DEBUG
36  atexit(DebugDumpMemory);
37  #endif
38  }
39  #else // USE_MEMORY_TRACKING
40 #define DEBUG_CLIENTBLOCK
41  inline void gxDbgDumpMem() {}
42  inline void gxInitDebug() {}
43 #endif // USE_MEMORY_TRACKING
44 
45 #endif