memory::arena
| Type | Class |
| Namespace | conjure::core::memory |
| Include File Path | engine/include/conjure/core/memory/arena.h |
| Source File Path | engine/src/core/memory/arena.cpp |
| API ↗ | Memory |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | explicit arena(
usize blockBytes = DEFAULT_ARENA_BLOCK_BYTES); | |
| public | arena(
arena &&other) noexcept; |
Important
Additional constructor overloads have been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~arena(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mBlockBytes | usize | DEFAULT_ | |
| private | mBlockCount | usize | 0 | |
| private | m | usize | 0 | |
| private | m | usize | 0 | |
| private | mCurrent | block * | nullptr | |
| private | mFirst | block * | nullptr |
Functions
Public
allocate
allocateReturns bytes bytes aligned to alignment (a power of two, up to and beyond 256). Bumps within the current block; a request that does not fit in a block of the configured size gets its own block. Returns nullptr for a zero-byte request, for an alignment that is not a power of two (asserts) and when the heap is exhausted.
block_bytes
block_bytes[[nodiscard]] usize block_bytes() const noexcept;Capacity of a regular block, as passed to the constructor.
bytes_allocated
bytes_allocated[[nodiscard]] usize bytes_allocated() const noexcept;Sum of the bytes handed out since the last reset(), excluding alignment padding.
bytes_reserved
bytes_reserved[[nodiscard]] usize bytes_reserved() const noexcept;Sum of the capacities of the blocks currently held (the usable bytes, excluding the small per-block header).
construct
constructtemplate <typename T, typename... Args> [[nodiscard]] T *construct(
Args &&...args);Allocates and constructs a T in the arena. T must be trivially destructible because reset() and release() never run destructors. Returns nullptr when allocation fails.
owns
owns[[nodiscard]] bool owns(
const void *pointer) const noexcept;True when pointer lies inside the used part of one of the arena's blocks. Linear in the block count; meant for assertions and tests.
release
releasevoid release() noexcept;Invalidates every allocation and returns every block to the heap. The arena stays usable; the next allocate() obtains a fresh block.
reset
resetvoid reset() noexcept;Invalidates every allocation. The first block whose capacity is the regular block size is kept for reuse, if there is one; every other block is returned to the heap. A dedicated oversized block therefore never survives a reset, wherever it sits in the chain: an arena whose first request of every cycle is oversized re-allocates that block every cycle, which a larger block size avoids.
Private
free_block
free_blockvoid free_block(
block *node) noexcept;