00001
00002
00003
#ifndef _XCTL_CHECKMEMORY_H_
00004
#define _XCTL_CHECKMEMORY_H_
00005
00006
#include <crtdbg.h>
00007
00008
00009
00010 _CrtMemState
s1,
s2,
s3;
00011
00012
00013
00014 void OutputHeading(
const char *explanation )
00015 {
00016 _RPT1( _CRT_WARN,
"\n\n-----%s----------------------------------------\n", explanation );
00017 }
00018
00019
00020 void OutputEnd()
00021 {
00022 _RPT0( _CRT_WARN,
"\n---------------------------------------------\n\n");
00023 }
00024
00025
00026 void CheckMemory(
const char *explanation)
00027 {
00028
OutputHeading(explanation);
00029 _CrtDumpMemoryLeaks();
00030
OutputEnd();
00031 }
00032
00033
00034 void SavePreState()
00035 {
00036 _CrtMemCheckpoint(&
s1);
00037 }
00038
00039
00040 void SavePostState()
00041 {
00042 _CrtMemCheckpoint(&
s2);
00043 }
00044
00045
00046 void DumpMemoryState(
const char *explanation)
00047 {
00048
if (_CrtMemDifference(&
s3,&
s1,&
s2))
00049 {
00050
OutputHeading(explanation);
00051 _CrtMemDumpStatistics( &
s3 );
00052
OutputEnd();
00053 }
00054 }
00055
00056
00057 void DumpMemoryObjects(
const char *explanation)
00058 {
00059
OutputHeading(explanation);
00060 _CrtMemDumpAllObjectsSince( &
s1);
00061
OutputEnd();
00062 }
00063
00064
00065
00066
#ifdef _DEBUG
00067
#define CHECKMEM(a) CheckMemory(a)
00068
#define PRE SavePreState()
00069
#define POST SavePostState()
00070
#define DUMPDIFF(a) DumpMemoryState(a)
00071
#define DUMPMEM(a) DumpMemoryObjects(a)
00072
#else
00073 #define CHECKMEM(a)
00074 #define PRE
00075 #define POST
00076 #define DUMPDIFF(a)
00077 #define DUMPMEM(a)
00078
#endif //_DEBUG
00079
00080
#endif //_XCTL_CHECKMEMORY_H_
00081