1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3 * Contains an allocator base class.
5 * \author Pierre Terdiman
6 * \date December, 19, 2003
8 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12 #ifndef ICEALLOCATOR_H
13 #define ICEALLOCATOR_H
21 class ICECORE_API Allocator
24 virtual void* malloc(size_t size, MemoryType type) = 0;
25 virtual void* mallocDebug(size_t size, const char* filename, udword line, const char* class_name, MemoryType type) = 0;
26 virtual void* realloc(void* memory, size_t size) = 0;
27 virtual void* shrink(void* memory, size_t size) = 0;
28 virtual void free(void* memory) = 0;
31 FUNCTION ICECORE_API Allocator* GetAllocator();
32 FUNCTION ICECORE_API bool SetAllocator(Allocator& allocator);
33 FUNCTION ICECORE_API void DumpMemory();
35 class ICECORE_API Allocateable
38 #ifdef DONT_TRACK_MEMORY_LEAKS
39 inline_ void* operator new (size_t size, MemoryType type) { return GetAllocator()->malloc(size, type); }
40 inline_ void* operator new (size_t size, const char * filename, int line, const char* class_name, MemoryType type) { return GetAllocator()->mallocDebug(size, filename, line, class_name, type); }
41 inline_ void* operator new[] (size_t size, MemoryType type) { return GetAllocator()->malloc(size, type); }
42 inline_ void* operator new[] (size_t size, const char * filename, int line, const char* class_name, MemoryType type) { return GetAllocator()->mallocDebug(size, filename, line, class_name, type); }
43 inline_ void operator delete (void* p) { GetAllocator()->free(p); }
44 inline_ void operator delete (void* p, MemoryType) { GetAllocator()->free(p); }
45 inline_ void operator delete (void* p, const char*, int, const char*, MemoryType) { GetAllocator()->free(p); }
46 inline_ void operator delete[] (void* p) { GetAllocator()->free(p); }
47 inline_ void operator delete[] (void* p, MemoryType) { GetAllocator()->free(p); }
48 inline_ void operator delete[] (void* p, const char*, int, const char*, MemoryType) { GetAllocator()->free(p); }
52 #endif // ICEALLOCATOR_H