Eneboo - Documentación para desarrolladores
|
00001 /* -*- C++ -*- */ 00002 00003 #ifndef _PADHEAP_H_ 00004 #define _PADHEAP_H_ 00005 00006 #include <assert.h> 00007 00008 // Pad object size requests. 00009 00010 template <int CacheLineSize, class SuperHeap> 00011 class PadHeap : public SuperHeap { 00012 public: 00013 00014 inline void * malloc (size_t sz) { 00015 return SuperHeap::malloc (roundup(sz)); 00016 } 00017 00018 private: 00019 00020 inline size_t roundup (size_t sz) { 00021 // NB: CacheLineSize MUST be a power of two. 00022 // The assertion below checks this. 00023 assert ((CacheLineSize & (CacheLineSize-1)) == 0); 00024 size_t roundup = (sz + CacheLineSize - 1) & ~((int) CacheLineSize-1); 00025 assert (roundup >= sz); 00026 return roundup; 00027 } 00028 }; 00029 00030 #endif