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;
52 const std::map<void*, const char*>& GetNameMap()
const {
67 template<
typename T,
typename... Args>
69 static_assert(std::is_constructible_v<T, Args...>,
"Type T must be constructible with given arguments.");
71 T* ptr =
static_cast<T*
>(AllocateRaw(
sizeof(T),
alignof(T),
typeid(T).name()));
74 new (ptr) T(std::forward<Args>(params)...);
77 return Grindstone::SharedPtr<T>(ptr, deleterFn);
80 template<
typename T,
typename... Args>
81 Grindstone::UniquePtr<T> AllocateUnique(Args&&... params) {
82 static_assert(std::is_constructible_v<T, Args...>,
"Type T must be constructible with given arguments.");
84 T* ptr =
static_cast<T*
>(AllocateRaw(
sizeof(T),
alignof(T),
typeid(T).name()));
87 new (ptr) T(std::forward<Args>(params)...);
90 return Grindstone::UniquePtr<T>(ptr, deleterFn);
93 template<
typename T,
typename... Args>
94 T* AllocateRaw(Args&&... params) {
95 static_assert(std::is_constructible_v<T, Args...>,
"Type T must be constructible with given arguments.");
97 T* ptr =
static_cast<T*
>(AllocateRaw(
sizeof(T),
alignof(T),
typeid(T).name()));
100 new (ptr) T(std::forward<Args>(params)...);
107 bool Free(
void* memPtr) {
108 if (memPtr !=
nullptr) {
112 reinterpret_cast<T*
>(memPtr)->~T();
119 void InitializeImpl(
void* ownedMemory,
size_t size);
121 void* startMemory =
nullptr;
122 void* endMemory =
nullptr;
125 std::function<void(
void*)> deleterFn;
126 size_t totalMemorySize = 0;
129 SearchPolicy searchPolicy = SearchPolicy::BestSearch;
130 bool shouldClear =
false;
131 bool hasAllocatedOwnMemory =
false;
134 std::map<void*, const char*> nameMap;