148 memory =
static_cast<char*
>(std::aligned_alloc(64, bytes));
151 assert(
memory &&
"Failed to allocate aligned memory");
169 std::size_t current =
offset;
172 if (current +
sizeof(T) >
capacity)
return nullptr;
174 char* ptr =
memory + current;
175 std::uintptr_t aligned = (
reinterpret_cast<std::uintptr_t
>(ptr) + (align - 1)) & ~(align - 1);
177 return reinterpret_cast<T*
>(aligned);
std::size_t capacity
Total capacity in bytes.
void reset()
Reset the allocator to reuse buffer (memory).
char * memory
Raw memory block.
T * allocate(std::size_t align=alignof(T))
Allocates memory for type T with specified alignment (default = alignof(T)).
~PoolAllocator()
Destroy the PoolAllocator and free the buffer.
std::size_t offset
Offset for bump allocation.
PoolAllocator(size_t bytes)
Construct a new PoolAllocator with a given size.