Eneboo - Documentación para desarrolladores
|
00001 #ifndef _PERCLASSHEAP_H 00002 #define _PERCLASSHEAP_H 00003 00004 #include <new> 00005 00020 namespace HL { 00021 00022 template <class SuperHeap> 00023 class PerClassHeap { 00024 public: 00025 inline void * operator new (size_t sz) { 00026 return getHeap()->malloc (sz); 00027 } 00028 inline void operator delete (void * ptr) { 00029 getHeap()->free (ptr); 00030 } 00031 inline void * operator new[] (size_t sz) { 00032 return getHeap()->malloc (sz); 00033 } 00034 inline void operator delete[] (void * ptr) { 00035 getHeap()->free (ptr); 00036 } 00037 // For some reason, g++ needs placement new to be overridden 00038 // as well, at least in conjunction with use of the STL. 00039 // Otherwise, this should be superfluous. 00040 inline void * operator new (size_t sz, void * p) { return p; } 00041 inline void * operator new[] (size_t sz, void * p) { return p; } 00042 00043 private: 00044 inline static SuperHeap * getHeap (void) { 00045 static SuperHeap theHeap; 00046 return &theHeap; 00047 } 00048 }; 00049 00050 } 00051 00052 #endif