Debian Codegraph @

libs/xpdf/xpdf-src/goo/gmempp.h

raw
1 //========================================================================
2 //
3 // gmempp.h
4 //
5 // Redefine the new and delete operators to call the debugging malloc.
6 //
7 // This is a hack: some libraries (Qt) allocate global objects and
8 // never free them, so this file #define's new to have an argument, so
9 // that we can differentiate our new calls from external library new
10 // calls. Calls from external libraries will not be counted when
11 // un-freed memory is listed. There's no guarantee that this will
12 // work in all cases: if some external library also defines a new
13 // operator that takes the same extra argument, things will break
14 // horribly.
15 //
16 // This entire .h file is wrapped in '#ifdef DEBUG_MEM'. I.e., if you
17 // don't define DEBUG_MEM, this hack goes away and can't cause any
18 // problems. Do not define DEBUG_MEM in production code.
19 //
20 // To use this .h file, it must be #included *after* all system
21 // includes. Calls to new in any modules that do not include this .h
22 // file will not be counted as un-freed memory.
23 //
24 //========================================================================
25
26 #ifndef GMEMPP_H
27 #define GMEMPP_H
28
29 #ifdef DEBUG_MEM
30
31 #include <stdlib.h>
32
33 extern void *operator new(size_t size, int dummy);
34 extern void *operator new[](size_t size, int dummy);
35
36 // These have to be defined (and declared) to avoid a compiler warning
37 // with Visual Studio.
38 extern void operator delete(void *p, int dummy);
39 extern void operator delete[](void *p, int dummy);
40
41 // This transforms 'new Foo(...)' into 'new (1) Foo(...)', which
42 // forces a call to the operator new variant with the 'int dummy' arg.
43 #define debug_new new (1)
44 #define new debug_new
45
46 #endif // DEBUG_MEM
47
48 #endif // GMEMPP_H