class
Lapis::Core::FrameArena
- Lapis::Core::FrameArena
- Reference
- Object
Overview
Linear pointer-bump frame scratchpad allocator reset once per tick.
All hot-path allocation methods (#alloc_bytes, #alloc_slice, #alloc_ptr, #push,
#copy_slice, #copy_array, #mark, #rewind, #reset!, #tick!) execute with
strictly ZERO GC heap allocations.
Defined in:
lapis/core/frame_arena.crConstant Summary
-
DEFAULT_ALIGNMENT =
8 -
DEFAULT_CAPACITY =
1048576
Constructors
-
.configure(capacity : Int32 = DEFAULT_CAPACITY) : FrameArena
Replaces or reconfigures the default frame arena with the given byte capacity.
-
.current : FrameArena
Returns the default active frame arena instance.
-
.frame(&) : FrameArena
Executes a block with the default frame arena and automatically calls
#tick!on completion. - .new(capacity : Int32 = DEFAULT_CAPACITY)
-
.reset! : FrameArena
Resets the default frame arena offset to zero without advancing the frame counter.
-
.scope(&) : FrameArena
Executes a scoped checkpoint block on the default frame arena, rewinding the bump pointer on exit.
-
.tick! : FrameArena
Resets the default frame arena for a new engine tick, incrementing its frame counter.
Class Method Summary
-
.align_up(offset : Int32, alignment : Int32 = DEFAULT_ALIGNMENT) : Int32
Aligns
#offsetupward to the nearest multiple ofalignment. -
.alloc_slice(type : T.class, count : Int32, *, alignment : Int32 = DEFAULT_ALIGNMENT) : Slice(T) forall T
Allocates a typed slice from the default frame arena.
-
.buffer(type : T.class, capacity : Int32, alignment : Int32 = DEFAULT_ALIGNMENT) : ArenaBuffer(T) forall T
Allocates an appendable
ArenaBuffer(T)from the default frame arena.
Instance Method Summary
-
#alloc_bytes(size : Int32, alignment : Int32 = DEFAULT_ALIGNMENT) : Bytes
Carves a contiguous
Bytesslice ofsizebytes aligned toalignment. -
#alloc_ptr(type : T.class, count : Int32 = 1, alignment : Int32 = DEFAULT_ALIGNMENT) : Pointer(T) forall T
Carves space for
countelements ofTand returns a typedPointer(T)(orPointer(T).nullif capacity is exceeded). -
#alloc_slice(type : T.class, count : Int32, value : T, *, alignment : Int32 = DEFAULT_ALIGNMENT) : Slice(T) forall T
Carves a contiguous
Slice(T)ofcountelements and initializes every slot tovalue. -
#alloc_slice(type : T.class, count : Int32, *, alignment : Int32 = DEFAULT_ALIGNMENT) : Slice(T) forall T
Carves a contiguous
Slice(T)ofcountelements from the linear scratchpad. - #allocation_count : Int32
-
#buffer(type : T.class, capacity : Int32, alignment : Int32 = DEFAULT_ALIGNMENT) : ArenaBuffer(T) forall T
Carves an appendable
ArenaBuffer(T)with fixed#capacityfrom the frame arena. -
#bytes_remaining : Int32
Alias for
#remaining. -
#bytes_used : Int32
Alias for
#used. -
#can_allocate?(size : Int32, alignment : Int32 = DEFAULT_ALIGNMENT) : Bool
Checks whether
sizebytes withalignmentcan fit in the remaining capacity. - #capacity : Int32
-
#clear! : self
Alias for
#reset!. -
#copy_array(src : Array(T), alignment : Int32 = DEFAULT_ALIGNMENT) : Slice(T) forall T
Copies an
Array(T)into the frame arena and returns the arena-backedSlice(T). -
#copy_slice(src : Slice(T), alignment : Int32 = DEFAULT_ALIGNMENT) : Slice(T) forall T
Copies a
Slice(T)into the frame arena and returns the arena-backedSlice(T). -
#empty? : Bool
Returns true if no bytes are currently allocated in this frame.
- #frame_count : UInt64
- #high_water_mark : Int32
-
#mark : Int32
Returns the current bump pointer offset for later
#rewind. - #offset : Int32
- #overflow_count : UInt64
-
#peak_bytes : Int32
Alias for
#high_water_mark. -
#push(value : T, alignment : Int32 = DEFAULT_ALIGNMENT) : Pointer(T) forall T
Writes a single value
Tinto the arena and returns aPointer(T)to its slot. -
#remaining : Int32
Bytes remaining before the arena reaches capacity.
-
#reset! : self
Resets the linear scratchpad offset and per-frame allocation counter in O(1) time.
-
#reset_stats! : self
Resets both the active bump pointer and all historical telemetry counters.
-
#rewind(mark_offset : Int32) : self
Rewinds the bump pointer to a previous
mark_offsetwithin[0, @offset]. -
#scope(&) : self
Executes a nested block and rewinds the arena bump pointer back to its pre-block mark.
-
#stats : FrameArenaStats
Captures a value-struct telemetry snapshot of this arena.
-
#tick : self
Alias for
#tick!(scanned by the Zero-Allocation AST Linter as a hot-path tick method). -
#tick! : self
Advances the frame tick counter and resets the bump pointer to 0 in O(1) time.
-
#tick_count : UInt64
Alias for
#frame_count. - #total_allocations : UInt64
-
#used : Int32
Bytes currently consumed in the active frame.
-
#utilization : Float64
Current frame utilization ratio (
0.0..1.0).
Instance methods inherited from class Object
try?(&)try? try?
Constructor Detail
Replaces or reconfigures the default frame arena with the given byte capacity.
Executes a block with the default frame arena and automatically calls #tick! on completion.
Resets the default frame arena offset to zero without advancing the frame counter.
Executes a scoped checkpoint block on the default frame arena, rewinding the bump pointer on exit.
Resets the default frame arena for a new engine tick, incrementing its frame counter.
Class Method Detail
Aligns #offset upward to the nearest multiple of alignment.
Allocates a typed slice from the default frame arena.
Allocates an appendable ArenaBuffer(T) from the default frame arena.
Instance Method Detail
Carves a contiguous Bytes slice of size bytes aligned to alignment.
Returns Bytes.empty and increments #overflow_count if capacity is exceeded.
Carves space for count elements of T and returns a typed Pointer(T)
(or Pointer(T).null if capacity is exceeded).
Carves a contiguous Slice(T) of count elements and initializes every slot to value.
Carves a contiguous Slice(T) of count elements from the linear scratchpad.
Returns Slice(T).empty if count <= 0 or capacity is exceeded.
Carves an appendable ArenaBuffer(T) with fixed #capacity from the frame arena.
Checks whether size bytes with alignment can fit in the remaining capacity.
Copies a Slice(T) into the frame arena and returns the arena-backed Slice(T).
Writes a single value T into the arena and returns a Pointer(T) to its slot.
Resets the linear scratchpad offset and per-frame allocation counter in O(1) time.
Resets both the active bump pointer and all historical telemetry counters.
Rewinds the bump pointer to a previous mark_offset within [0, @offset].
Executes a nested block and rewinds the arena bump pointer back to its pre-block mark.