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 7 8#include <debug.h> 9 10 11struct DebugAllocPool; 12typedef struct DebugAllocPool debug_alloc_pool; 13 14 15#ifdef __cplusplus 16extern "C" { 17#endif 18 19debug_alloc_pool* create_debug_alloc_pool(); 20void delete_debug_alloc_pool(debug_alloc_pool* pool); 21void* debug_malloc(size_t size); 22void* debug_calloc(size_t num, size_t size); 23void debug_free(void* address); 24void debug_heap_init(); 25 26#ifdef __cplusplus 27} 28#endif 29 30 31#ifdef __cplusplus 32 33struct kdebug_alloc_t {}; 34extern const kdebug_alloc_t kdebug_alloc; 35 36inline void* 37operator new(size_t size, const kdebug_alloc_t&) throw() 38{ 39 return debug_malloc(size); 40} 41 42namespace DebugAlloc { 43 template<typename Type> 44 inline void 45 destroy(Type* object) 46 { 47 if (object != NULL) { 48 object->~Type(); 49 debug_free(object); 50 // NOTE: Doesn't work for multiple inheritence! 51 } 52 } 53} 54 55struct DebugAllocPoolScope { 56 DebugAllocPoolScope() 57 { 58 fPool = create_debug_alloc_pool(); 59 } 60 61 ~DebugAllocPoolScope() 62 { 63 delete_debug_alloc_pool(fPool); 64 } 65 66private: 67 DebugAllocPool* fPool; 68}; 69 70#endif // __cplusplus 71 72#endif /* _KERNEL_DEBUG_HEAP_H */ 73