#ifndef _GLOBALHEAP_H_ #define _GLOBALHEAP_H_ #include "hoardsuperblock.h" #include "processheap.h" namespace Hoard { template class GlobalHeap { class bogusThresholdFunctionClass { public: static inline bool function (int, int, size_t) { // We *never* cross the threshold for a process heap. return false; } }; public: GlobalHeap (void) : theHeap (getHeap()) { } typedef ProcessHeap SuperHeap; typedef HoardSuperblock SuperblockType; void put (void * s, size_t sz) { assert (s); assert (((SuperblockType *) s)->isValidSuperblock()); theHeap->put ((typename SuperHeap::SuperblockType *) s, sz); } SuperblockType * get (size_t sz, void * dest) { SuperblockType * s = reinterpret_cast (theHeap->get (sz, reinterpret_cast(dest))); if (s) { assert (s->isValidSuperblock()); } return s; } private: SuperHeap * theHeap; inline static SuperHeap * getHeap (void) { static double theHeapBuf[sizeof(SuperHeap) / sizeof(double) + 1]; static SuperHeap * theHeap = new (&theHeapBuf[0]) SuperHeap; return theHeap; } // Prevent copying. GlobalHeap (const GlobalHeap&); GlobalHeap& operator=(const GlobalHeap&); }; }; #endif