2018-10-07 03:42:33 +00:00
|
|
|
#pragma once
|
2017-09-12 15:27:48 +00:00
|
|
|
|
2019-09-22 21:52:05 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-01-16 06:59:00 +00:00
|
|
|
#include "Runtime/IAllocator.hpp"
|
2019-09-22 21:52:05 +00:00
|
|
|
#include "Runtime/RetroTypes.hpp"
|
2022-01-16 06:59:00 +00:00
|
|
|
#include "Runtime/CSmallAllocPool.hpp"
|
|
|
|
#include "Runtime/CMediumAllocPool.hpp"
|
2017-09-12 15:27:48 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2020-10-30 22:56:02 +00:00
|
|
|
class CGameAllocator : public IAllocator {
|
2022-01-16 06:59:00 +00:00
|
|
|
public:
|
|
|
|
private:
|
|
|
|
class SGameMemInfo {
|
|
|
|
public:
|
|
|
|
u32 x0_priorGuard = 0xefefefef;
|
2020-09-08 17:58:55 +00:00
|
|
|
size_t x4_len = 0;
|
2022-01-16 06:59:00 +00:00
|
|
|
const char* x8_fileAndLine;
|
2020-09-08 17:58:55 +00:00
|
|
|
const char* xc_type;
|
2022-01-16 06:59:00 +00:00
|
|
|
void* x10_prev = nullptr;
|
|
|
|
void* x14_next = nullptr;
|
2020-09-08 17:58:55 +00:00
|
|
|
void* x18_ = nullptr;
|
2022-01-16 06:59:00 +00:00
|
|
|
u32 x1c_postGuard = 0xeaeaeaea;
|
|
|
|
public:
|
|
|
|
void* GetPrev() { return x10_prev; }
|
|
|
|
void SetPrev(void* prev) { x10_prev = prev; }
|
|
|
|
void* GetNext() { return x14_next; }
|
|
|
|
void SetNext(void* next) { x14_next = next; }
|
|
|
|
u32 GetPrevMaskedFlags();
|
|
|
|
u32 GetNextMaskedFlags();
|
|
|
|
void SetTopOfHeapAllocated(bool topOfHeap);
|
2018-12-08 05:30:43 +00:00
|
|
|
};
|
2022-01-16 06:59:00 +00:00
|
|
|
|
|
|
|
u8 x4_;
|
|
|
|
u8 x5_;
|
|
|
|
u8 x6_;
|
|
|
|
u8 x7_;
|
|
|
|
u32 x8_heapSize;
|
|
|
|
SGameMemInfo* xc_first;
|
|
|
|
SGameMemInfo* x10_last;
|
|
|
|
std::array<SGameMemInfo*, 16> x14_bins;
|
|
|
|
u32 x54_;
|
|
|
|
FOutOfMemoryCb x58_oomCallBack;
|
|
|
|
void* x5c_oomTarget;
|
|
|
|
std::unique_ptr<CSmallAllocPool> x60_smallPool;
|
|
|
|
void* x64_smallAllocBookKeeping;
|
|
|
|
void* x68_smallAllocMainData;
|
|
|
|
bool x6c_;
|
|
|
|
u32 x70_;
|
|
|
|
std::unique_ptr<CMediumAllocPool> x74_mediumPool;
|
|
|
|
void* x78_;
|
|
|
|
bool x7c_;
|
|
|
|
u32 x80_;
|
|
|
|
u32 x84_;
|
|
|
|
u32 x88_;
|
|
|
|
u32 x8c_;
|
|
|
|
u32 x90_heapSize2;
|
|
|
|
u32 x94_;
|
|
|
|
u32 x98_;
|
|
|
|
u32 x9c_;
|
|
|
|
u32 xa0_;
|
|
|
|
u32 xa4_;
|
|
|
|
u32 xa8_;
|
|
|
|
u32 xac_;
|
|
|
|
u32 xb0_;
|
|
|
|
u32 xb4_;
|
|
|
|
u32 xb8_fakeStatics = 0;
|
|
|
|
u32 xbc_;
|
|
|
|
|
2020-09-08 17:58:55 +00:00
|
|
|
static u32 GetFreeBinEntryForSize(size_t len);
|
2021-06-05 05:25:46 +00:00
|
|
|
SGameMemInfo* GetMemInfoFromBlockPtr(void* ptr) {
|
|
|
|
return reinterpret_cast<SGameMemInfo*>(reinterpret_cast<void*>(intptr_t(ptr) - sizeof(SGameMemInfo)));
|
|
|
|
}
|
|
|
|
|
2020-10-30 22:56:02 +00:00
|
|
|
public:
|
2020-12-03 03:01:57 +00:00
|
|
|
bool Initialize() override; // const COsContext& ctx);
|
2021-06-05 05:25:46 +00:00
|
|
|
void* Alloc(size_t size) override;
|
|
|
|
bool Free(void* ptr) override;
|
2020-12-03 03:01:57 +00:00
|
|
|
void ReleaseAll() override;
|
2021-06-05 05:25:46 +00:00
|
|
|
void* AllocSecondary(size_t size) override;
|
|
|
|
bool FreeSecondary(void* ptr) override;
|
2020-12-03 03:01:57 +00:00
|
|
|
void ReleaseAllSecondary() override;
|
2022-01-16 06:59:00 +00:00
|
|
|
void SetOutOfMemoryCallback(FOutOfMemoryCb cb, void* target) override;
|
|
|
|
s32 EnumAllocations(IAllocator::FEnumAllocationsCb cb, const void* ptr, bool b) override;
|
2021-06-05 05:25:46 +00:00
|
|
|
SAllocInfo GetAllocInfo(void* ptr) override;
|
|
|
|
void OffsetFakeStatics(s32 offset) override;
|
2022-01-16 06:59:00 +00:00
|
|
|
SMetrics GetMetrics() override;
|
|
|
|
void AllocSecondary();
|
|
|
|
void FreeSecondary();
|
|
|
|
void* Alloc();
|
2017-09-12 15:27:48 +00:00
|
|
|
};
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|