prime/include/Kyoto/Alloc/CMemory.hpp

34 lines
1.2 KiB
C++
Raw Normal View History

#ifndef _CMEMORY
#define _CMEMORY
#include "types.h"
2022-10-12 08:07:35 +00:00
#include "Kyoto/Alloc/IAllocator.hpp"
2022-10-12 08:07:35 +00:00
class COsContext;
class CMemory {
static IAllocator* mpAllocator;
static bool mInitialized;
public:
static void Startup(COsContext& ctx);
static void Shutdown();
static void SetAllocator(COsContext& ctx, IAllocator& allocator);
static IAllocator* GetAllocator();
static void* Alloc(size_t len, IAllocator::EHint hint, IAllocator::EScope scope, IAllocator::EType type, const CCallStack& callstack);
static void Free(const void* ptr);
static void SetOutOfMemoryCallback(IAllocator::FOutOfMemoryCb callback, const void* context);
static void OffsetFakeStatics(int);
};
2022-10-01 06:19:09 +00:00
void* operator new(size_t sz, const char*, const char*);
void* operator new[](size_t sz, const char*, const char*);
inline void* operator new(size_t sz) { return operator new(sz, "??(??)", nullptr); }
inline void* operator new[](size_t sz) { return operator new[](sz, "??(??)", nullptr); }
// placement new
2022-10-01 06:19:09 +00:00
inline void* operator new(size_t n, void* ptr) { return ptr; };
inline void operator delete(void* ptr) { CMemory::Free(ptr); }
2022-10-01 06:19:09 +00:00
inline void operator delete[](void* ptr) { CMemory::Free(ptr); }
#endif // _CMEMORY