logos.lang.writ.allocator
Module lang · package logos-lang
Types
structAllocator
struct Allocator
Owns a singly-linked list of never-moved segments.
Bump-allocates within current, appends a new segment when full, frees all on drop.
Implements: Drop
Fields
current: *mut Segment
The segment currently being bump-allocated into.
head: *mut Segment
First segment — the walk start for freeing all segments en masse.
seg_size: i64
Default data capacity in bytes for newly appended segments.
Methods
fn drop(self: Allocator) -> void
Frees all segments en masse; a no-op if allocator_free already ran (idempotent).
structSegment
struct Segment
A never-moved chunk: an inline header followed by cap bytes of data.
Implements: SelfDescribing
Fields
cap: i64
Data capacity in bytes for this segment, excluding the header.
data: [u8]
Inline flexible-array tail holding the segment’s raw data bytes.
next: *mut Segment
Absolute pointer to the next segment, or null if this is the last one.
used: i64
Bump cursor: bytes already handed out within the data region.
Functions
fnallocator_alloc
fn allocator_alloc(a: *mut Allocator, size: i64, align: i64) -> *mut u8
Bump-allocates size bytes at align from the allocator, appending a new
segment if the current one is full. align must be a power of two; the
allocator floors it to 2 (a Ref’d object’s low bit must be 0). Returns a
pointer into a never-moved segment (stable for the allocator’s lifetime), or
null on OOM.
fnallocator_free
fn allocator_free(a: *mut Allocator) -> void
Frees all segments en masse. The allocator must not be used afterwards.
Idempotent: nulls head/current, so a second call (or the Drop impl after
an explicit free) walks a null list and is a no-op — no double-free.
fnallocator_new
fn allocator_new(seg_size: i64) -> Allocator
Creates an allocator with an initial segment of seg_size data bytes.
On OOM the returned allocator has a null head (allocator_alloc then returns null).