2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CSMALLALLOCPOOL
|
|
|
|
#define _CSMALLALLOCPOOL
|
2022-09-11 18:45:19 +00:00
|
|
|
|
|
|
|
#include <types.h>
|
|
|
|
|
2022-09-20 04:35:24 +00:00
|
|
|
#include <Kyoto/Alloc/AllocatorCommon.hpp>
|
|
|
|
|
2022-09-11 18:45:19 +00:00
|
|
|
class CSmallAllocPool {
|
|
|
|
public:
|
2022-09-18 06:05:46 +00:00
|
|
|
CSmallAllocPool(uint len, void* mainData, void* bookKeeping);
|
|
|
|
void* FindFree(int len);
|
|
|
|
void* Alloc(uint size);
|
|
|
|
bool Free(const void* ptr);
|
|
|
|
|
2022-09-20 04:35:24 +00:00
|
|
|
bool PtrWithinPool(const void* ptr) const {
|
2022-10-09 05:37:23 +00:00
|
|
|
return uint((reinterpret_cast< const uchar* >(ptr) - reinterpret_cast< uchar* >(x0_mainData)) /
|
|
|
|
4) < x8_numBlocks;
|
2022-09-18 06:05:46 +00:00
|
|
|
}
|
2022-09-20 04:35:24 +00:00
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
uint GetIndexFromPtr(const void* ptr) const {
|
2022-10-09 05:37:23 +00:00
|
|
|
return ((const uchar*)ptr - x0_mainData) / kPointerSize;
|
2022-10-09 05:13:17 +00:00
|
|
|
}
|
2022-10-09 05:37:23 +00:00
|
|
|
long GetEntryValue(uint idx) const { return (long)*((uchar*)x4_bookKeeping + idx); }
|
|
|
|
uchar* GetPtrFromIndex(unsigned int idx) const {
|
|
|
|
return static_cast< uchar* >(x0_mainData) + (idx << 3);
|
2022-10-09 05:13:17 +00:00
|
|
|
}
|
2022-09-20 04:35:24 +00:00
|
|
|
|
|
|
|
uint GetNumBlocksAvailable() const { return x18_numBlocksAvailable; }
|
|
|
|
uint GetTotalEntries() const { return x8_numBlocks; }
|
|
|
|
uint GetAllocatedSize() const { return x8_numBlocks - x18_numBlocksAvailable; }
|
|
|
|
uint GetNumAllocs() const { return x1c_numAllocs; }
|
|
|
|
|
|
|
|
private:
|
2022-09-11 18:45:19 +00:00
|
|
|
void* x0_mainData;
|
|
|
|
void* x4_bookKeeping;
|
|
|
|
int x8_numBlocks;
|
|
|
|
void* xc_cachedBookKeepingOffset;
|
|
|
|
int x10_;
|
|
|
|
int x14_;
|
|
|
|
uint x18_numBlocksAvailable;
|
|
|
|
uint x1c_numAllocs;
|
|
|
|
};
|
2022-10-09 05:13:17 +00:00
|
|
|
|
|
|
|
#endif // _CSMALLALLOCPOOL
|