Eneboo - Documentación para desarrolladores
|
00001 // -*- C++ -*- 00002 00003 #if !defined(_BINS4K_H_) 00004 #define _BINS4K_H_ 00005 00006 #include "bins.h" 00007 #include "sassert.h" 00008 00009 namespace HL { 00010 00011 template <class Header> 00012 class bins<Header, 4096> { 00013 00014 public: 00015 bins (void) {} 00016 00017 enum { NUM_BINS = 33 }; 00018 enum { BIG_OBJECT = 4096 - sizeof(Header) }; 00019 00020 static const size_t _bins[NUM_BINS]; 00021 00022 static inline int getSizeClass (size_t sz) { 00023 assert (sz <= BIG_OBJECT); 00024 if (sz < 8) { 00025 return 0; 00026 } else if (sz <= 128) { 00027 return ((sz + 7) >> 3) - 1; 00028 } else { 00029 return slowLookupSizeClass (sz); 00030 } 00031 } 00032 00033 static inline size_t getClassSize (const int i) { 00034 assert (i >= 0); 00035 assert (i < NUM_BINS); 00036 return _bins[i]; 00037 } 00038 00039 private: 00040 00041 static int slowLookupSizeClass (const size_t sz) { 00042 // Find the size class for a given object size 00043 // (the smallest i such that _bins[i] >= sz). 00044 int sizeclass = 0; 00045 while (_bins[sizeclass] < sz) 00046 { 00047 sizeclass++; 00048 assert (sizeclass < NUM_BINS); 00049 } 00050 return sizeclass; 00051 } 00052 00053 sassert<(BIG_OBJECT > 0)> verifyHeaderSize; 00054 00055 }; 00056 } 00057 00058 template <class Header> 00059 const size_t HL::bins<Header, 4096>::_bins[NUM_BINS] = {8UL, 16UL, 24UL, 32UL, 40UL, 48UL, 56UL, 64UL, 72UL, 80UL, 88UL, 96UL, 104UL, 112UL, 120UL, 128UL, 152UL, 176UL, 208UL, 248UL, 296UL, 352UL, 416UL, 496UL, 592UL, 704UL, 856UL, 1024UL, 1224UL, 1712UL, 2048UL, 3416UL, 4096UL - sizeof(Header)}; 00060 00061 #endif 00062