Debian Codegraph @

protolib/include/protoCheck.h

raw
1
2 #ifndef _PROTO_CHECK
3 #define _PROTO_CHECK
4
5 // This module provides compile-time optional "new" and "delete" operators
6 // for Protolib (or any code that #include "protoDefs.h" or this). These
7 // operator keep track of current memory allocations (of the new operator)
8 // and which source code file and line number from which the allocation was
9 // made. This can be useful for debugging purposes and should only be
10 // enabled for such purposes as there is a performance penalty when this
11 // is enabled.
12
13 // At compile time, use -DUSE_PROTO_CHECK (or uncomment the line below)
14 // that defines that macro.
15
16 // The current memory allocations can be "logged" via a call to
17 // ProtoCheckLogAllocations(). In the future some additional memory
18 // usage statistics (e.g. total size of allocations, peak, etc)
19 // might be added. This is _not_ a replacement for other tools such
20 // as "valgrind", etc but useful for Protolib-based code.
21
22 #include <stdio.h> // for FILE*
23
24 // UNCOMMENT this next line to enable "ProtoCheck" (or use -DUSE_PROTO_CHECK for your compiler)
25 //#define USE_PROTO_CHECK
26
27 #ifdef USE_PROTO_CHECK
28
29 #include <new>
30
31 #ifndef _PROTO_CHECK_IMPL
32
33 void* operator new(size_t size, const char* file, int line);
34
35 void* operator new[](size_t size, const char* file, int line);
36
37 void operator delete(void* p) throw();
38
39 void operator delete[](void *p) throw();
40
41 #define new new(__FILE__, __LINE__)
42
43 // This trick is used to log delete operator file/line
44 // info just before the call to delete is made.
45
46 void ProtoCheckCacheInfo(const char* file, int line);
47 //void ProtoCheckDelete(void* p, const char* file, int line);
48
49 #define delete ProtoCheckCacheInfo(__FILE__, __LINE__), delete
50
51 #endif // !_PROTO_CHECK_IMPL
52
53 #endif // USE_PROTO_CHECK
54
55 void ProtoCheckResetLogging();
56 void ProtoCheckLogAllocations(FILE* filePtr);
57
58 #endif // _PROTO_CHECK