-
Notifications
You must be signed in to change notification settings - Fork 1
/
memtracer.h
78 lines (62 loc) · 1.9 KB
/
memtracer.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
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
#ifndef MEM_TRACER_H
#define MEM_TRACER_H
#include <stddef.h>
#ifdef __cplusplus
#include <new>
extern "C" {
#endif
#define MSG_ERR_HM_MALLOC "malloc() failed for allocation descriptors hashmap."
// Allocation descriptors hashmap size, increase to lower the load shown by dumpAlloc
//#define ALLOC_TABLE_SIZE 1733
#define ALLOC_TABLE_SIZE 2048
// Allocation descriptor hashmap structs
typedef struct allocdescr
{
void* ptr;
char* file;
int line;
size_t size;
} allocdescr;
typedef struct allocnode
{
allocdescr* info;
struct allocnode* next;
} allocnode;
typedef struct allochashmap
{
size_t size;
allocnode** table;
} allochashmap;
void* tracingMalloc(size_t size, const char* name, int line);
void* tracingRealloc(void* ptr, int size, const char* name, int line);
void* tracingCalloc(int num, int size, const char* name, int line);
void tracingFree(void* ptr);
void dumpAlloc();
#ifndef MEM_TRACER_C
#define malloc(s) tracingMalloc(s,__FILE__,__LINE__)
#define realloc(p,s) tracingRealloc(p,s,__FILE__,__LINE__)
#define calloc(n,s) tracingCalloc(n,s,__FILE__,__LINE__)
#define free(p) tracingFree(p)
#endif //ifndef MEM_TRACER_C
#ifdef __cplusplus
}
#endif
#ifndef MEM_TRACER_C
#ifdef __cplusplus
//void* operator new(size_t) throw(std::bad_alloc);
void* operator new(size_t) throw();
void* operator new(size_t, const char* name, int line);
//void* operator new[] (size_t) throw(std::bad_alloc);
void* operator new[](size_t) throw();
void* operator new[] (size_t, const char* name, int line);
void operator delete(void*) throw();
void operator delete(void*, const char* name, int line);
void operator delete[](void*) throw();
void operator delete[](void*, const char* name, int line);
#define tracingNew new (__FILE__,__LINE__)
#define tracingDelete delete
#define new tracingNew
#define delete tracingDelete
#endif //ifdef _cplusplus
#endif //ifndef MEM_TRACER_C
#endif //ifndef MEM_TRACER_H