1 | #ifndef UTIL_H__ |
1 | #ifndef UTIL_H__ |
2 | #define UTIL_H__ |
2 | #define UTIL_H__ |
|
|
3 | |
|
|
4 | //#define PREFER_MALLOC |
3 | |
5 | |
4 | #if __GNUC__ >= 3 |
6 | #if __GNUC__ >= 3 |
5 | # define is_constant(c) __builtin_constant_p (c) |
7 | # define is_constant(c) __builtin_constant_p (c) |
6 | #else |
8 | #else |
7 | # define is_constant(c) 0 |
9 | # define is_constant(c) 0 |
… | |
… | |
133 | |
135 | |
134 | // for symmetry |
136 | // for symmetry |
135 | template<typename T> |
137 | template<typename T> |
136 | inline void sfree (T *ptr, int n = 1) throw () |
138 | inline void sfree (T *ptr, int n = 1) throw () |
137 | { |
139 | { |
|
|
140 | #ifdef PREFER_MALLOC |
|
|
141 | free (ptr); |
|
|
142 | #else |
138 | g_slice_free1 (n * sizeof (T), (void *)ptr); |
143 | g_slice_free1 (n * sizeof (T), (void *)ptr); |
|
|
144 | #endif |
139 | } |
145 | } |
140 | |
146 | |
141 | // a STL-compatible allocator that uses g_slice |
147 | // a STL-compatible allocator that uses g_slice |
142 | // boy, this is verbose |
148 | // boy, this is verbose |
143 | template<typename Tp> |
149 | template<typename Tp> |