5#include <Common/Memory/Allocators/DynamicAllocator.hpp>
6#include <Common/String.hpp>
8namespace Grindstone::Memory::AllocatorCore {
16 bool Initialize(
size_t sizeInMegs);
17 void CloseAllocator();
19 StringRef AllocateString(
size_t size);
20 StringRef AllocateString(Grindstone::StringRef srcString);
22 bool FreeWithoutDestructor(
void* memPtr);
30 void* AllocateRaw(
size_t size,
size_t alignment,
const char* debugName);
34 return GetAllocatorState()->dynamicAllocator.MakeShared(ptr);
39 return GetAllocatorState()->dynamicAllocator.MakeUnique(ptr);
42 template<
typename T,
typename... Args>
44 return GetAllocatorState()->dynamicAllocator.AllocateUnique<T>(std::forward<Args>(params)...);
47 template<
typename T,
typename... Args>
49 return GetAllocatorState()->dynamicAllocator.AllocateShared<T>(std::forward<Args>(params)...);
52 template<
typename T,
typename... Args>
53 T* Allocate(Args&&... params) {
54 T* ptr =
static_cast<T*
>(GetAllocatorState()->dynamicAllocator.AllocateRaw(
sizeof(T),
alignof(T),
typeid(T).name()));
57 std::construct_at(ptr, std::forward<Args>(params)...);
64 T* AllocateArray(
size_t arraySize) {
65 T* ptr =
static_cast<T*
>(GetAllocatorState()->dynamicAllocator.AllocateRaw(
sizeof(T) * arraySize,
alignof(T),
typeid(T).name()));
69 template<
typename T,
typename... Args>
70 T* AllocateArray(
size_t arraySize, Args&&... params) {
71 T* ptr =
static_cast<T*
>(GetAllocatorState()->dynamicAllocator.AllocateRaw(
sizeof(T) * arraySize,
alignof(T),
typeid(T).name()));
74 for (
size_t i = 0; i < arraySize; ++i) {
75 new (ptr + i) T(std::forward<Args>(params)...);
82 template<
typename T,
typename... Args>
83 T* AllocateNamed(
const char* debugName, Args&&... params) {
84 T* ptr =
static_cast<T*
>(GetAllocatorState()->dynamicAllocator.AllocateRaw(
sizeof(T),
alignof(T), debugName));
87 new (ptr) T(std::forward<Args>(params)...);
94 T* AllocateArrayNamed(
const char* debugName,
size_t arraySize) {
95 T* ptr =
static_cast<T*
>(GetAllocatorState()->dynamicAllocator.AllocateRaw(
sizeof(T) * arraySize,
alignof(T), debugName));
99 template<
typename T,
typename... Args>
100 T* AllocateArrayNamed(
const char* debugName,
size_t arraySize, Args&&... params) {
101 T* ptr =
static_cast<T*
>(GetAllocatorState()->dynamicAllocator.AllocateRaw(
sizeof(T) * arraySize,
alignof(T), debugName));
102 if (ptr !=
nullptr) {
104 for (
size_t i = 0; i < arraySize; ++i) {
105 new (ptr + i) T(std::forward<Args>(params)...);
113 bool Free(T* memPtr) {
114 if (memPtr ==
nullptr) {
118 reinterpret_cast<T*
>(memPtr)->~T();
119 GetAllocatorState()->dynamicAllocator.Free(memPtr);
A dynamic allocator represented by a linked list.
Definition DynamicAllocator.hpp:19
Definition SharedPtr.hpp:5
Definition UniquePtr.hpp:7
Definition MemoryAllocator.hpp:9