3 #ifndef BLOCK_ALLOCATOR_H
4 #define BLOCK_ALLOCATOR_H
9 #include "BlockReferenceManager.h"
13 #define ENABLE_BA_PANIC 1
15 #define BA_PANIC(x) { PANIC(x); BlockAllocator::fPanic = true; }
21 class BlockAllocator
{
23 BlockAllocator(size_t areaSize
);
26 status_t
InitCheck() const;
28 BlockReference
*AllocateBlock(size_t usableSize
);
29 void FreeBlock(BlockReference
*block
);
30 BlockReference
*ResizeBlock(BlockReference
*block
, size_t usableSize
);
32 size_t GetAvailableBytes() const { return fAreaCount
* fAreaSize
; }
33 size_t GetFreeBytes() const { return fFreeBytes
; }
34 size_t GetUsedBytes() const { return fAreaCount
* fAreaSize
42 bool SanityCheck(bool deep
= false) const;
43 bool CheckArea(Area
*area
);
44 bool CheckBlock(Block
*block
, size_t minSize
= 0);
45 bool CheckBlock(BlockReference
*reference
, size_t minSize
= 0);
46 void GetAllocationInfo(AllocationInfo
&info
);
49 inline Area
*_AreaForBlock(Block
*block
);
50 Block
*_AllocateBlock(size_t usableSize
, bool dontCreateArea
= false);
51 void _FreeBlock(Area
*area
, Block
*block
, bool freeReference
);
52 inline void _RethinkAreaBucket(Area
*area
, AreaBucket
*bucket
,
53 bool needsDefragmenting
);
54 inline bool _DefragmentingRecommended();
58 BlockReferenceManager fReferenceManager
;
70 #endif // BLOCK_ALLOCATOR_H