… | |
… | |
20 | */ |
20 | */ |
21 | |
21 | |
22 | #ifndef UTIL_H__ |
22 | #ifndef UTIL_H__ |
23 | #define UTIL_H__ |
23 | #define UTIL_H__ |
24 | |
24 | |
25 | #define DEBUG_POISON 0xaa // poison memory before freeing it if != 0 |
25 | #define DEBUG_POISON 0x00 // poison memory before freeing it if != 0 |
26 | #define DEBUG_SALLOC 0 // add a debug wrapper around all sallocs |
26 | #define DEBUG_SALLOC 0 // add a debug wrapper around all sallocs |
27 | #define PREFER_MALLOC 0 // use malloc and not the slice allocator |
27 | #define PREFER_MALLOC 0 // use malloc and not the slice allocator |
28 | |
28 | |
29 | #if __GNUC__ >= 3 |
29 | #if __GNUC__ >= 3 |
30 | # define is_constant(c) __builtin_constant_p (c) |
30 | # define is_constant(c) __builtin_constant_p (c) |
… | |
… | |
222 | slice_alloc -= n * sizeof (T); |
222 | slice_alloc -= n * sizeof (T); |
223 | if (DEBUG_POISON) memset (ptr, DEBUG_POISON, n * sizeof (T)); |
223 | if (DEBUG_POISON) memset (ptr, DEBUG_POISON, n * sizeof (T)); |
224 | g_slice_free1 (n * sizeof (T), (void *)ptr); |
224 | g_slice_free1 (n * sizeof (T), (void *)ptr); |
225 | assert (slice_alloc >= 0);//D |
225 | assert (slice_alloc >= 0);//D |
226 | } |
226 | } |
|
|
227 | } |
|
|
228 | |
|
|
229 | // nulls the pointer |
|
|
230 | template<typename T> |
|
|
231 | inline void sfree0 (T *&ptr, int n = 1) throw () |
|
|
232 | { |
|
|
233 | sfree<T> (ptr, n); |
|
|
234 | ptr = 0; |
227 | } |
235 | } |
228 | |
236 | |
229 | // makes dynamically allocated objects zero-initialised |
237 | // makes dynamically allocated objects zero-initialised |
230 | struct zero_initialised |
238 | struct zero_initialised |
231 | { |
239 | { |