2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _IALLOCATOR
|
|
|
|
#define _IALLOCATOR
|
2022-07-21 04:47:03 +00:00
|
|
|
|
|
|
|
#include "Kyoto/Alloc/CMemory.hpp"
|
|
|
|
#include "types.h"
|
2022-09-20 04:35:24 +00:00
|
|
|
#include <stddef.h>
|
2022-07-21 04:47:03 +00:00
|
|
|
|
|
|
|
class COsContext;
|
|
|
|
class CCallStack;
|
|
|
|
|
|
|
|
class IAllocator {
|
|
|
|
public:
|
2022-08-09 23:03:51 +00:00
|
|
|
enum EHint {
|
2022-09-20 04:35:24 +00:00
|
|
|
kHI_None = 0,
|
|
|
|
kHI_TopOfHeap = (1 << 0),
|
2022-08-09 23:03:51 +00:00
|
|
|
kHI_RoundUpLen = (1 << 1),
|
|
|
|
};
|
2022-09-20 04:35:24 +00:00
|
|
|
|
2022-08-09 23:03:51 +00:00
|
|
|
enum EScope {
|
|
|
|
kSC_Unk0,
|
2022-09-20 04:35:24 +00:00
|
|
|
kSC_Unk1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EType {
|
|
|
|
kTP_Unk0,
|
|
|
|
kTP_Unk1,
|
2022-08-09 23:03:51 +00:00
|
|
|
};
|
2022-07-21 04:47:03 +00:00
|
|
|
|
2022-08-09 23:03:51 +00:00
|
|
|
struct SMetrics {
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x0_heapSize;
|
|
|
|
uint x4_;
|
|
|
|
uint x8_;
|
|
|
|
uint xc_;
|
|
|
|
uint x10_;
|
|
|
|
uint x14_heapSize2; // Remaining heap size?
|
|
|
|
uint x18_;
|
|
|
|
uint x1c_;
|
|
|
|
uint x20_;
|
|
|
|
uint x24_;
|
|
|
|
uint x28_;
|
|
|
|
uint x2c_smallNumAllocs;
|
|
|
|
uint x30_smallAllocatedSize;
|
|
|
|
uint x34_smallRemainingSize;
|
|
|
|
uint x38_mediumNumAllocs;
|
|
|
|
uint x3c_mediumAllocatedSize;
|
|
|
|
uint x40_mediumBlocksAvailable;
|
|
|
|
uint x44_;
|
|
|
|
uint x48_;
|
|
|
|
uint x4c_;
|
|
|
|
uint x50_mediumTotalAllocated;
|
|
|
|
uint x54_fakeStatics;
|
2022-09-18 06:05:46 +00:00
|
|
|
SMetrics(uint heapSize, uint unk1, uint unk2, uint unk3, uint unk4, uint heapSize2, uint unk5,
|
|
|
|
uint unk6, uint unk7, uint unk8, uint unk9, uint smallAllocNumAllocs,
|
|
|
|
uint smallAllocAllocatedSize, uint smallAllocRemainingSize, uint mediumAllocNumAllocs,
|
|
|
|
uint mediumAllocAllocatedSize, uint mediumAllocBlocksAvailable, uint unk10, uint unk11,
|
|
|
|
uint unk12, uint mediumAllocTotalAllocated, uint fakeStatics);
|
2022-09-20 04:35:24 +00:00
|
|
|
SMetrics(const SMetrics& other);
|
2022-08-09 23:03:51 +00:00
|
|
|
};
|
2022-07-21 04:47:03 +00:00
|
|
|
|
2022-08-09 23:03:51 +00:00
|
|
|
struct SAllocInfo {
|
2022-09-22 06:03:38 +00:00
|
|
|
const void* x0_infoPtr;
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x4_len;
|
2022-09-22 06:03:38 +00:00
|
|
|
bool x8_isAllocated;
|
2022-08-09 23:03:51 +00:00
|
|
|
bool x9_;
|
2022-09-22 06:03:38 +00:00
|
|
|
const char* xc_fileAndLine;
|
2022-08-09 23:03:51 +00:00
|
|
|
const char* x10_type;
|
2022-09-22 06:03:38 +00:00
|
|
|
|
|
|
|
SAllocInfo(const void* ptr, uint len, bool isAllocated, bool b2, const char* fileAndLine,
|
|
|
|
const char* type)
|
|
|
|
: x0_infoPtr(ptr)
|
|
|
|
, x4_len(len)
|
|
|
|
, x8_isAllocated(isAllocated)
|
|
|
|
, x9_(b2)
|
|
|
|
, xc_fileAndLine(fileAndLine)
|
|
|
|
, x10_type(type) {}
|
2022-08-09 23:03:51 +00:00
|
|
|
};
|
2022-07-21 04:47:03 +00:00
|
|
|
|
2022-09-20 04:35:24 +00:00
|
|
|
typedef const bool (*FOutOfMemoryCb)(const void*, uint);
|
2022-08-09 23:03:51 +00:00
|
|
|
typedef const bool (*FEnumAllocationsCb)(const SAllocInfo& info, const void* ptr);
|
|
|
|
virtual ~IAllocator();
|
2022-07-21 04:47:03 +00:00
|
|
|
|
2022-08-09 23:03:51 +00:00
|
|
|
virtual bool Initialize(COsContext& ctx) = 0;
|
|
|
|
virtual void Shutdown() = 0;
|
2022-10-01 06:19:09 +00:00
|
|
|
virtual void* Alloc(size_t size, EHint hint, EScope scope, EType type, const CCallStack& cs) = 0;
|
2022-09-20 04:35:24 +00:00
|
|
|
virtual bool Free(const void* ptr) = 0;
|
2022-08-09 23:03:51 +00:00
|
|
|
virtual void ReleaseAll() = 0;
|
2022-10-01 06:19:09 +00:00
|
|
|
virtual void* AllocSecondary(size_t size, EHint hint, EScope scope, EType type,
|
2022-09-18 06:05:46 +00:00
|
|
|
const CCallStack& cs) = 0;
|
2022-09-20 04:35:24 +00:00
|
|
|
virtual bool FreeSecondary(const void* ptr) = 0;
|
2022-08-09 23:03:51 +00:00
|
|
|
virtual void ReleaseAllSecondary() = 0;
|
|
|
|
virtual void SetOutOfMemoryCallback(FOutOfMemoryCb cb, const void* data) = 0;
|
2022-09-22 06:03:38 +00:00
|
|
|
virtual int EnumAllocations(FEnumAllocationsCb func, const void* ptr, bool b) const = 0;
|
2022-08-09 23:03:51 +00:00
|
|
|
virtual SAllocInfo GetAllocInfo(const void* ptr) const = 0;
|
2022-09-05 04:01:13 +00:00
|
|
|
virtual void OffsetFakeStatics(int offset) = 0;
|
2022-08-09 23:03:51 +00:00
|
|
|
virtual SMetrics GetMetrics() const = 0;
|
2022-07-21 04:47:03 +00:00
|
|
|
};
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _IALLOCATOR
|