liarsdice::performance::MemoryArena class

Memory arena for temporary allocations.

Stack-based allocation pattern for temporary objects with bulk deallocation.

Constructors, destructors, conversion operators

MemoryArena(std::size_t size = 1024*1024) explicit

Public functions

auto allocate(std::size_t size, std::size_t alignment = alignof(std::max_align_t)) -> void*
Allocate memory from arena.
template<typename T, typename... Args>
auto construct(Args && ... args) -> T*
Allocate typed object.
void reset() noexcept
Reset arena to initial state.
auto used() const -> std::size_t noexcept
Get current memory usage.
auto capacity() const -> std::size_t noexcept
Get total arena size.

Function documentation

void* liarsdice::performance::MemoryArena::allocate(std::size_t size, std::size_t alignment = alignof(std::max_align_t))

Allocate memory from arena.

Parameters
size Number of bytes
alignment Alignment requirement
Returns Pointer to allocated memory

template<typename T, typename... Args>
T* liarsdice::performance::MemoryArena::construct(Args && ... args)

Allocate typed object.

Template parameters
T Object type
Args Constructor arguments
Parameters
args Arguments to forward
Returns Pointer to constructed object

std::size_t liarsdice::performance::MemoryArena::used() const noexcept

Get current memory usage.

Returns Bytes currently allocated

std::size_t liarsdice::performance::MemoryArena::capacity() const noexcept

Get total arena size.

Returns Total bytes available