btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / kernel / debug_heap.h
blob552a07a8cda47d4ad998a3a8c584f09b39f6cf0e
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _KERNEL_DEBUG_HEAP_H
6 #define _KERNEL_DEBUG_HEAP_H
8 #include <debug.h>
11 struct DebugAllocPool;
12 typedef struct DebugAllocPool debug_alloc_pool;
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
19 debug_alloc_pool* create_debug_alloc_pool();
20 void delete_debug_alloc_pool(debug_alloc_pool* pool);
21 void* debug_malloc(size_t size);
22 void* debug_calloc(size_t num, size_t size);
23 void debug_free(void* address);
24 void debug_heap_init();
26 #ifdef __cplusplus
28 #endif
31 #ifdef __cplusplus
33 struct kdebug_alloc_t {};
34 extern const kdebug_alloc_t kdebug_alloc;
36 inline void*
37 operator new(size_t size, const kdebug_alloc_t&) throw()
39 return debug_malloc(size);
42 namespace DebugAlloc {
43 template<typename Type>
44 inline void
45 destroy(Type* object)
47 if (object != NULL) {
48 object->~Type();
49 debug_free(object);
50 // NOTE: Doesn't work for multiple inheritence!
55 struct DebugAllocPoolScope {
56 DebugAllocPoolScope()
58 fPool = create_debug_alloc_pool();
61 ~DebugAllocPoolScope()
63 delete_debug_alloc_pool(fPool);
66 private:
67 DebugAllocPool* fPool;
70 #endif // __cplusplus
72 #endif /* _KERNEL_DEBUG_HEAP_H */