File: debugMemory.h

package info (click to toggle)
between 6%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 3,532 kB
  • sloc: cpp: 28,110; php: 718; ansic: 638; objc: 245; sh: 236; makefile: 99; perl: 67
file content (127 lines) | stat: -rw-r--r-- 2,442 bytes parent folder | download | duplicates (30)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Modification History
 *
 * 2002-October-17 Jason Rohrer
 * Created.
 *
 * 2002-October-18  Jason Rohrer
 * Added static initialization counting class for MemoryTrack.
 *
 * 2002-October-20  Jason Rohrer
 * Removed delete macro trick that was causing crashes in tinyxml.
 */


#ifndef DEBUG_MEMORY_INCLUDED
#define DEBUG_MEMORY_INCLUDED




#ifdef DEBUG_MEMORY

#include "minorGems/util/development/memory/MemoryTrack.h"



// internal function prototypes
void *debugMemoryNew( unsigned int inSize,
                      const char *inFileName, int inLine );

void *debugMemoryNewArray( unsigned int inSize,
                           const char *inFileName, int inLine );

void debugMemoryDelete( void *inPointer );

void debugMemoryDeleteArray( void *inPointer );



// overrided primitive operators... must be inline?



/**
 * Overrides the new operator to track memory allocations.
 *
 * @param inSize the size of the allocation.
 * @param inFileName the name of the source file where the allocation
 *   occurred.
 * @param inLine the line in the source file where the allocation occurred.
 */
inline void *operator new( unsigned int inSize,
                           const char *inFileName, int inLine ) {
    return debugMemoryNew( inSize, inFileName, inLine );
    }



/**
 * Overrides the new [] operator to track memory allocations.
 *
 * @param inSize the size of the allocation.
 * @param inFileName the name of the source file where the allocation
 *   occurred.
 * @param inLine the line in the source file where the allocation occurred.
 */
inline void * operator new [] ( unsigned int inSize,
                                const char *inFileName, int inLine ) {

    return debugMemoryNewArray( inSize, inFileName, inLine );
    }




/**
 * Overrides the delete operator to track memory allocations.
 *
 * @param inPointer a pointer to the memory to deallocate.
 */
inline void operator delete( void *inPointer ) {
    debugMemoryDelete( inPointer );
    }



/**
 * Overrides the delete [] operator to track memory allocations.
 *
 * @param inPointer a pointer to the memory to deallocate.
 */
inline void operator delete [] ( void *inPointer ) {
    debugMemoryDeleteArray( inPointer );
    }



#endif





// macro trickery to pass file name and line number into new

#ifdef DEBUG_MEMORY
#define DEBUG_NEW new( __FILE__, __LINE__ )
#else
#define DEBUG_NEW new
#endif



#define new DEBUG_NEW



#endif