31 enum class SearchPolicy {
38 bool Initialize(
size_t size);
39 void Initialize(
void* ownedMemory,
size_t size);
41 void* AllocateRaw(
size_t size,
size_t alignment,
const char* debugName);
42 bool Free(
void* memPtr);
46 size_t GetTotalMemorySize()
const;
47 size_t GetPeakSize()
const;
48 size_t GetUsedSize()
const;
49 void* GetMemory()
const;
51 template<
typename T,
typename... Args>
53 T* ptr =
static_cast<T*
>(AllocateRaw(
sizeof(T),
alignof(T),
typeid(T).name()));
56 new (ptr) T(std::forward<Args>(params)...);
59 return SharedPtr<T>(ptr, deleterFn);
62 template<
typename T,
typename... Args>
64 T* ptr =
static_cast<T*
>(AllocateRaw(
sizeof(T),
alignof(T),
typeid(T).name()));
67 new (ptr) T(std::forward<Args>(params)...);
70 return UniquePtr<T>(ptr, deleterFn);
73 template<
typename T,
typename... Args>
74 T* AllocateRaw(Args&&... params) {
75 T* ptr =
static_cast<T*
>(AllocateRaw(
sizeof(T),
alignof(T),
typeid(T).name()));
78 new (ptr) T(std::forward<Args>(params)...);
85 bool Free(
void* memPtr) {
86 if (memPtr !=
nullptr) {
90 reinterpret_cast<T*
>(memPtr)->~T();
97 void FindAvailable(
size_t size,
size_t alignment,
size_t& padding, FreeHeader*& previousFreeHeader, FreeHeader*& freeHeader)
const;
98 void FindAvailableFirst(
size_t size,
size_t alignment,
size_t& padding, FreeHeader*& previousFreeHeader, FreeHeader*& freeHeader)
const;
99 void FindAvailableBest(
size_t size,
size_t alignment,
size_t& padding, FreeHeader*& previousFreeHeader, FreeHeader*& freeHeader)
const;
100 void Coalesce(FreeHeader* previousNode, FreeHeader* freeNode);
101 void InitializeImpl(
void* ownedMemory,
size_t size);
103 void* startMemory =
nullptr;
104 void* endMemory =
nullptr;
105 FreeHeader* firstFreeHeader =
nullptr;
107 std::function<void(
void*)> deleterFn;
108 size_t totalMemorySize = 0;
111 SearchPolicy searchPolicy = SearchPolicy::BestSearch;
112 bool shouldClear =
false;
113 bool hasAllocatedOwnMemory =
false;
116 std::map<void*, const char*> nameMap;