source: liacs/MIR2010/SourceCode/memoryleak.h@ 175

Last change on this file since 175 was 95, checked in by Rick van der Zwet, 15 years ago

Bad boy, improper move of directory

File size: 1.3 KB
RevLine 
[95]1#ifndef _INCLUDE_MEMORYLEAKH
2#define _INCLUDE_MEMORYLEAKH
3
4#pragma once
5
6/////////////////////////////////////////////////////////////////////////
7// for debugging memory leaks type "{,,msvcr80d.dll}_crtBreakAlloc" in
8// the watch window to set the allocation number at which to break
9// dynamically or insert the statement "_CrtSetBreakAlloc([alloc#]);"
10// at the beginning of the main() function.
11/////////////////////////////////////////////////////////////////////////
12#define _CRTDBG_MAP_ALLOC
13#include <crtdbg.h>
14
15#ifdef _DEBUG
16#define NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
17#else
18#define NEW new
19#endif
20
21
22// memory leak finder
23class FindMemoryLeaks
24{
25#ifdef _DEBUG
26public:
27 FindMemoryLeaks() {}
28 FindMemoryLeaks(long alloc) { _CrtSetBreakAlloc(alloc); }
29 ~FindMemoryLeaks() { _CrtDumpMemoryLeaks(); }
30#endif
31};
32
33class FindMemoryLeaksExt
34{
35#ifdef _DEBUG
36public:
37 FindMemoryLeaksExt()
38 {
39 _CrtMemCheckpoint(&m_checkpoint);
40 };
41 ~FindMemoryLeaksExt()
42 {
43 _CrtMemState checkpoint;
44 _CrtMemCheckpoint(&checkpoint);
45 _CrtMemState diff;
46 if (_CrtMemDifference(&diff, &m_checkpoint, &checkpoint))
47 _CrtMemDumpStatistics(&diff);
48 //_CrtMemDumpAllObjectsSince(&diff);
49 };
50private:
51 _CrtMemState m_checkpoint;
52#endif
53};
54
55#endif
Note: See TracBrowser for help on using the repository browser.