-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug_new.h
46 lines (39 loc) · 1.25 KB
/
debug_new.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* debug_new.h 1.7 2003/07/03
*
* Header file for checking leakage by operator new
*
* By Wu Yongwei
*
*/
#ifndef _DEBUG_NEW_H
#define _DEBUG_NEW_H
#include <new>
/* Prototypes */
bool check_leaks();
void* operator new(size_t size, const char* file, int line, void* add);
void* operator new[](size_t size, const char* file, int line, void* add);
#ifndef NO_PLACEMENT_DELETE
void operator delete(void* pointer, const char* file, int line);
void operator delete[](void* pointer, const char* file, int line);
#endif // NO_PLACEMENT_DELETE
void operator delete[](void*); // MSVC 6 requires this declaration
void ShowMemoryLeak();
#define SHOW_MEMORY_LEAK_REPO ShowMemoryLeak()
/* Macros */
#ifndef DEBUG_NEW_NO_NEW_REDEFINITION
#define new DEBUG_NEW
#define DEBUG_NEW new(__FILE__, __LINE__)
#define debug_new new
#else
#define debug_new new(__FILE__, __LINE__)
#endif // DEBUG_NEW_NO_NEW_REDEFINITION
#ifdef DEBUG_NEW_EMULATE_MALLOC
#include <stdlib.h>
#define malloc(s) ((void*)(debug_new char[s]))
#define free(p) delete[] (char*)(p)
#endif // DEBUG_NEW_EMULATE_MALLOC
/* Control flags */
extern bool new_verbose_flag; // default to false: no verbose information
extern bool new_autocheck_flag; // default to true: call check_leaks() on exit
#endif // _DEBUG_NEW_H