More CGameAllocator

This commit is contained in:
Phillip Stephens 2021-06-04 22:25:46 -07:00
parent cdb4666b96
commit 4ba5db133d
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
2 changed files with 36 additions and 17 deletions

View File

@ -32,7 +32,15 @@ void CGameAllocator::FreeSecondary() {}
void CGameAllocator::ReleaseAllSecondary() {}
void CGameAllocator::SetOutOfMemoryCallback() {}
void CGameAllocator::EnumAllocations() {}
SAllocInfo CGameAllocator::GetAllocInfo() { return SAllocInfo(); }
void CGameAllocator::sub80351138() {}
IAllocator::SAllocInfo CGameAllocator::GetAllocInfo(void* ptr) {
SGameMemInfo* info = GetMemInfoFromBlockPtr(ptr);
return {.x0_infoPtr = info,
.x4_len = info->x4_len,
.x8_hasPrevious = info->x10_prev != nullptr,
.x9_ = false,
.xc_fileAndLne = info->x8_line,
.x10_type = info->xc_type};
}
void CGameAllocator::OffsetFakeStatics(s32 offset) { xb8_fakeStatics += offset; }
void CGameAllocator::GetMetrics() {}
} // namespace metaforce

View File

@ -15,8 +15,6 @@ public:
CCallStack(int lineNum, const char* lineStr, const char* type) : x0_line(lineStr), x4_type(type) {}
};
struct SAllocInfo {};
enum class EHint {
Unk = (1 << 0),
RoundUpLen = (1 << 1),
@ -34,18 +32,27 @@ enum class EType {
class IAllocator {
public:
struct SAllocInfo {
void* x0_infoPtr;
size_t x4_len;
bool x8_hasPrevious;
bool x9_;
const char* xc_fileAndLne;
const char* x10_type;
};
virtual bool Initialize() = 0; // const COSContext& ctx) = 0;
virtual void* Alloc() = 0;
virtual s32 Free(void* ptr) = 0;
virtual void* Alloc(size_t size) = 0;
virtual bool Free(void* ptr) = 0;
virtual void ReleaseAll() = 0;
virtual void AllocSecondary() = 0;
virtual void FreeSecondary() = 0;
virtual void* AllocSecondary(size_t size) = 0;
virtual bool FreeSecondary(void* ptr) = 0;
virtual void ReleaseAllSecondary() = 0;
virtual void SetOutOfMemoryCallback() = 0;
virtual void EnumAllocations() = 0;
virtual SAllocInfo GetAllocInfo() = 0;
virtual void sub80351138() = 0;
virtual SAllocInfo GetAllocInfo(void* ptr) = 0;
virtual void OffsetFakeStatics(s32 offset) = 0;
virtual void GetMetrics() = 0;
};
@ -61,21 +68,25 @@ class CGameAllocator : public IAllocator {
u32 x1c_canary = 0xeaeaeaea;
};
static u32 GetFreeBinEntryForSize(size_t len);
SGameMemInfo* GetMemInfoFromBlockPtr(void* ptr) {
return reinterpret_cast<SGameMemInfo*>(reinterpret_cast<void*>(intptr_t(ptr) - sizeof(SGameMemInfo)));
}
std::array<SGameMemInfo*, 16> x14_bins;
s32 xb8_fakeStatics = 0;
public:
bool Initialize() override; // const COsContext& ctx);
void* Alloc() override;
s32 Free(void* ptr) override;
void* Alloc(size_t size) override;
bool Free(void* ptr) override;
void ReleaseAll() override;
void AllocSecondary() override;
void FreeSecondary() override;
void* AllocSecondary(size_t size) override;
bool FreeSecondary(void* ptr) override;
void ReleaseAllSecondary() override;
void SetOutOfMemoryCallback() override;
void EnumAllocations() override;
SAllocInfo GetAllocInfo() override;
void sub80351138() override;
SAllocInfo GetAllocInfo(void* ptr) override;
void OffsetFakeStatics(s32 offset) override;
void GetMetrics() override;
};
} // namespace metaforce