2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CMEDIUMALLOCPOOL
|
|
|
|
#define _CMEDIUMALLOCPOOL
|
2022-09-20 04:35:24 +00:00
|
|
|
|
2023-10-03 05:36:22 +00:00
|
|
|
#include <rstl/auto_ptr.hpp>
|
2022-09-20 04:35:24 +00:00
|
|
|
#include <rstl/list.hpp>
|
|
|
|
|
2023-10-03 05:36:22 +00:00
|
|
|
struct SMediumAllocPuddle {
|
2023-10-05 10:09:48 +00:00
|
|
|
SMediumAllocPuddle(const uint numBlocks, void* data, const bool canErase);
|
2023-10-03 05:36:22 +00:00
|
|
|
~SMediumAllocPuddle();
|
|
|
|
void* FindFree(uint blockCount);
|
|
|
|
void* FindFreeEntry(uint blockCount);
|
2023-10-04 06:56:48 +00:00
|
|
|
void Free(const void* ptr);
|
|
|
|
|
|
|
|
const uint GetNumBlocks() const { return x14_numBlocks; }
|
|
|
|
const uint GetNumAllocs() const { return x18_numAllocs; }
|
|
|
|
const uint GetNumEntries() const { return x1c_numEntries; }
|
2023-10-05 10:09:48 +00:00
|
|
|
const bool CanErase() const { return x20_canErase; }
|
2023-10-04 06:56:48 +00:00
|
|
|
const uint GetPtrOffset(const void* ptr) const { return (uchar*)ptr - x0_mainData.get(); }
|
|
|
|
static ushort GetBlockOffset(const void* ptrA, const void* ptrB);
|
2023-10-03 06:47:00 +00:00
|
|
|
static void InitBookKeeping(uchar* bookKeepingPtr, const ushort blockCount);
|
2023-10-03 05:36:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
rstl::auto_ptr< void > x0_mainData;
|
|
|
|
uchar* x8_bookKeeping;
|
|
|
|
uchar* xc_cachedBookKeepingAddr;
|
2023-10-05 10:09:48 +00:00
|
|
|
uint x10_unused;
|
2023-10-03 05:36:22 +00:00
|
|
|
uint x14_numBlocks;
|
|
|
|
uint x18_numAllocs;
|
|
|
|
uint x1c_numEntries;
|
2023-10-05 10:09:48 +00:00
|
|
|
bool x20_canErase : 1;
|
2023-10-03 05:36:22 +00:00
|
|
|
};
|
|
|
|
|
2022-09-20 04:35:24 +00:00
|
|
|
class CMediumAllocPool {
|
|
|
|
public:
|
2022-10-09 05:13:17 +00:00
|
|
|
rstl::list< SMediumAllocPuddle > x0_list;
|
2023-10-03 05:36:22 +00:00
|
|
|
rstl::list< SMediumAllocPuddle >::node* x18_lastNodePrev;
|
2023-10-01 19:28:38 +00:00
|
|
|
CMediumAllocPool();
|
2022-10-09 05:13:17 +00:00
|
|
|
void* Alloc(uint size);
|
|
|
|
bool HasPuddles() const;
|
2023-10-04 06:56:48 +00:00
|
|
|
void AddPuddle(const uint, void*, const bool);
|
2022-10-09 05:13:17 +00:00
|
|
|
void ClearPuddles();
|
2022-09-20 04:35:24 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
int Free(const void* ptr);
|
2022-09-20 04:35:24 +00:00
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
uint GetTotalEntries();
|
|
|
|
uint GetNumBlocksAvailable();
|
|
|
|
uint GetNumAllocs();
|
2023-10-01 19:28:38 +00:00
|
|
|
|
|
|
|
static CMediumAllocPool* gMediumAllocPtr;
|
2022-09-20 04:35:24 +00:00
|
|
|
};
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CMEDIUMALLOCPOOL
|