Skip to content

Engine → Core

frame_allocator.h

Declarations for frame_allocator.h.

Classes

File Description
memory::frame_allocator Per-frame scratch memory shared by every thread. One arena of arenaBytes is carved into thread blocks of threadBlockBytes with a single atomic bump; each thread then allocates inside its own block from a thread_local slot without any synchronisation. When a request does not fit the thread's block the thread grabs a new one (the remainder of the old block is abandoned); when the arena is exhausted, or a request is larger than a block, the allocation falls back to tracked_allocate and overflow_count() grows. Overflow blocks are released by reset(). Thread safety: allocate() and the getters may be called from any thread concurrently and are lock-free (overflow uses a lock-free push; every counter the getters read is atomic). reset() must not run concurrently with allocate(): the engine resets at FRAME_BEGIN with no job in flight. reset() bumps the epoch, which invalidates every thread's cached block so a stale thread_local cursor is never reused. Implementation note: the thread_local slot is {owner, epoch, cursor, end, arenaExhausted}; a thread that alternates between two frame allocators re-acquires a block on every switch. Epochs are process-unique, so a slot left over from a destroyed allocator never matches a new one that happens to live at the same address.

Forward Declarations

memory::frame_allocator::overflow_block

struct overflow_block;