Merge branch 'master' of ssh://demsky.eecs.uci.edu/home/git/constraint_compiler into...
[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 _MY_MEMORY_H
15 #define _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
29 static inline void *ourmalloc(size_t size) { return malloc(size); }
30 static inline void ourfree(void *ptr) { free(ptr); }
31 static inline void *ourcalloc(size_t count, size_t size) { return calloc(count, size); }
32 static inline void *ourrealloc(void *ptr, size_t size) { return realloc(ptr, size); }
33
34 #define MEMALLOC                                                                                                         \
35         void * operator new(size_t size) {                       \
36                 return ourmalloc(size);                                                          \
37         }                                                                                                                                                                                                        \
38         void operator delete(void *p, size_t size) {                     \
39                 ourfree(p);                                                                                                                                                      \
40         }                                                                                                                                                                                                        \
41         void * operator new[](size_t size) {                                                     \
42                 return ourmalloc(size);                                                                                                  \
43         }                                                                                                                                                                                                                \
44         void operator delete[](void *p, size_t size) {                   \
45                 ourfree(p);                                                                                                                                                              \
46         }                                                                                                                                                                                                                                                                                       \
47         void * operator new(size_t size, void *p) {                             /* placement new */ \
48                 return p;                                                                                                                                                                                                                                               \
49         }
50
51 #endif/* _MY_MEMORY_H */