lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
default_heap.h
00001 /*****************************************************/
00002 /* lean Memory                  (c) Tobias Zirr 2011 */
00003 /*****************************************************/
00004 
00005 #ifndef LEAN_MEMORY_DEFAULT_HEAP
00006 #define LEAN_MEMORY_DEFAULT_HEAP
00007 
00008 #ifndef LEAN_DEFAULT_HEAP
00009 
00010     #include "crt_heap.h"
00013     #define LEAN_DEFAULT_HEAP crt_heap
00014 
00015 #endif
00016 
00017 namespace lean
00018 {
00019     namespace memory
00020     {
00022         typedef LEAN_DEFAULT_HEAP default_heap;
00023 
00024     } // namespace
00025 
00026     using memory::default_heap;
00027 
00028 } // namespace
00029 
00030 #ifdef DOXYGEN_READ_THIS
00031 
00032 
00033     #define LEAN_OVERRIDE_NEW
00034     #undef LEAN_OVERRIDE_NEW
00035 #endif
00036 
00037 #ifdef LEAN_OVERRIDE_NEW
00038 
00039     #if LEAN_DEFAULT_HEAP == crt_heap
00040         // CRT uses global operators new / delete, overriding them would cause chaos
00041         #error Cannot override new using the CRT heap
00042     #else
00043 
00044         inline void* operator new(size_t size)
00045         {
00046             return lean::memory::default_heap::allocate(size);
00047         }
00049         inline void operator delete(void *memory)
00050         {
00051             lean::memory::default_heap::free(memory);
00052         }
00054         inline void* operator new[](size_t size)
00055         {
00056             return lean::memory::default_heap::allocate(size);
00057         }
00059         inline void operator delete[](void *memory)
00060         {
00061             lean::memory::default_heap::free(memory);
00062         }
00063     #endif
00064 
00065 #endif
00066 
00067 #endif