File: INCLUDE\UTILS\CheckMemory.h
1 // Makros zum Aufspüren von MemoryLeaks
2
3 #ifndef _XCTL_CHECKMEMORY_H_
4 #define _XCTL_CHECKMEMORY_H_
5
6 #include <crtdbg.h>
7
8
9 //Memory states
10 _CrtMemState s1, s2, s3;
11
12
13 // This routine place comments at the head of a section of debug output
14 void OutputHeading( const char *explanation )
15 {
16 _RPT1( _CRT_WARN, "\n\n-----%s----------------------------------------\n", explanation );
17 }
18
19 // This routine place an end-comment at the head of a section of debug output
20 void OutputEnd()
21 {
22 _RPT0( _CRT_WARN, "\n---------------------------------------------\n\n");
23 }
24
25 // This routine checks memory and place comments at the head of a section of debug output
26 void CheckMemory(const char *explanation)
27 {
28 OutputHeading(explanation);
29 _CrtDumpMemoryLeaks();
30 OutputEnd();
31 }
32
33 // This routine saves pre-execution memory state
34 void SavePreState()
35 {
36 _CrtMemCheckpoint(&s1);
37 }
38
39 // This routine saves post-execution memory state
40 void SavePostState()
41 {
42 _CrtMemCheckpoint(&s2);
43 }
44
45 // This routine dumps difference between pre- and post-execution memory state
46 void DumpMemoryState(const char *explanation)
47 {
48 if (_CrtMemDifference(&s3,&s1,&s2))
49 {
50 OutputHeading(explanation);
51 _CrtMemDumpStatistics( &s3 );
52 OutputEnd();
53 }
54 }
55
56 // This routine dumps all objects instantiated since pre-execution memory state
57 void DumpMemoryObjects(const char *explanation)
58 {
59 OutputHeading(explanation);
60 _CrtMemDumpAllObjectsSince( &s1);
61 OutputEnd();
62 }
63
64
65 //
66 #ifdef _DEBUG
72 #else
73 #define CHECKMEM(a)
74 #define PRE
75 #define POST
76 #define DUMPDIFF(a)
77 #define DUMPMEM(a)
78 #endif //_DEBUG
79
80 #endif //_XCTL_CHECKMEMORY_H_
81
82