09ea7cdb535a85f88c5669c302423fbb8d399af3
[satune.git] / src / mymemory.h
1 /*      Copyright (c) 2015 Regents of the University of California
2  *
3  *      Author: Brian Demsky <bdemsky@uci.edu>
4  *
5  *      This program is free software; you can redistribute it and/or
6  *      modify it under the terms of the GNU General Public License
7  *      version 2 as published by the Free Software Foundation.
8  */
9
10 /** @file mymemory.h
11  *  @brief Memory allocation functions.
12  */
13
14 #ifndef CSAT_MY_MEMORY_H
15 #define CSAT_MY_MEMORY_H
16 #include <limits.h>
17 #include <stddef.h>
18 #include <stdlib.h>
19
20 #include "config.h"
21
22 /*
23    void * ourmalloc(size_t size);
24    void ourfree(void *ptr);
25    void * ourcalloc(size_t count, size_t size);
26    void * ourrealloc(void *ptr, size_t size);
27  */
28 void * model_malloc(size_t size);
29 void model_free(void *ptr);
30 void * model_calloc(size_t count, size_t size);
31 void * model_realloc(void *ptr, size_t size);
32
33
34 #define ourmalloc model_malloc
35 #define ourfree model_free
36 #define ourrealloc model_realloc
37 #define ourcalloc model_calloc
38 /*
39 static inline void *ourmalloc(size_t size) { return malloc(size); }
40 static inline void ourfree(void *ptr) { free(ptr); }
41 static inline void *ourcalloc(size_t count, size_t size) { return calloc(count, size); }
42 static inline void *ourrealloc(void *ptr, size_t size) { return realloc(ptr, size); }*/
43
44 #define CMEMALLOC                           \
45         void *operator new(size_t size) {       \
46                 return ourmalloc(size);                \
47         }                                                  \
48         void operator delete(void *p, size_t size) {       \
49                 ourfree(p);                                      \
50         }                                                  \
51         void *operator new[](size_t size) {               \
52                 return ourmalloc(size);                          \
53         }                                                    \
54         void operator delete[](void *p, size_t size) {       \
55                 ourfree(p);                                        \
56         }                                                                     \
57         void *operator new(size_t size, void *p) {                                                                                                                      /* placement new */ \
58                 return p;                                                           \
59         }
60
61 #endif/* _MY_MEMORY_H */