size_t AllocPool::LargestFreeChunk() { int word = 0; for (int i=3; i>=0; --i) { if (mBinBlocks[i]) { word = i; break; } } int binBits = (int)mBinBlocks[word]; int bitPosition = NUMBITS(binBits) - 1; int index = (word << 5) + bitPosition; AllocChunkPtr bin = mBins + index; //postbuf("** %p %p %p %p\n", mBinBlocks[0], mBinBlocks[1], mBinBlocks[2], mBinBlocks[3]); //postbuf("%d %d %d %p %p %p\n", word, bitPosition, index, binBits, bin->Prev(), bin->Next()); AllocChunkPtr candidate; size_t maxsize = 0; for (candidate = bin->Prev(); candidate != bin; candidate = candidate->Prev()) { size_t candidate_size = candidate->Size(); maxsize = sc_max(maxsize, candidate_size); //postbuf(" %d %d\n", maxsize, candidate_size); } /*for (int i=0; i<kNumAllocBins; ++i) { bin = mBins + i; if (bin->Prev() != bin) { postbuf("* %d %d\n", i, bin->Prev()->Size()); } }*/ return maxsize; }
inline int pathInt_depth( const int pathInt) { return ( NUMBITS(pathInt) - 1 ); // root is depth 0, its kids are depth 1, etc }