1 #include <stdlib.h>
2 #ifndef ALLOC_PROXY_H_
3 #define ALLOC_PROXY_H_
4 
5 #include "macros.h"
6 
7 /* This header file defines mynew/mynew/mymalloc/myfree, where deletions
8  * require the size to be provided -- this makes it easier to plug in
9  * memory debuggers.
10  */
11 #define xxxUSE_ELETRIC_ALLOC
12 
13 /* announce C prototypes with appropriate linkage. */
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 static inline void * mymalloc(size_t s);
18 static inline void myfree(void * p, size_t s);
19 #ifdef __cplusplus
20 }
21 #endif
22 
23 #ifdef USE_ELETRIC_ALLOC
24 #include "electric_alloc.h"
mymalloc(size_t s)25 static inline void * mymalloc(size_t s) { return electric_alloc(s); }
myfree(void * p,size_t s)26 static inline void myfree(void * p, size_t s) { electric_free(p, s); }
27 #else
mymalloc(size_t s)28 static inline void * mymalloc(size_t s) { return malloc(s); }
myfree(void * p,size_t s MAYBE_UNUSED)29 static inline void myfree(void * p, size_t s MAYBE_UNUSED) { free(p); }
30 #endif
31 
32 #ifdef __cplusplus
33 #ifdef USE_ELETRIC_ALLOC
34 template<typename T>
mynew(size_t s)35 inline T * mynew(size_t s) { return electric_new<T>(s); }
36 template<typename T>
mydelete(T * & p,size_t s)37 inline void mydelete(T * & p, size_t s) { electric_delete(p,s); p = NULL; }
38 #else
39 template<typename T>
mynew(size_t s)40 inline T * mynew(size_t s) { return new T[s]; }
41 template<typename T>
mydelete(T * & p,size_t s MAYBE_UNUSED)42 inline void mydelete(T * & p, size_t s MAYBE_UNUSED) { delete[] p; p = NULL; }
43 #endif
44 #endif
45 
46 #endif	/* ALLOC_PROXY_H_ */
47