std.heap
bump arena; growable (64 KiB chunks), reserved, or over a fixed buffer
MemError
Section titled “MemError”pub MemError :: errors { out_of_memory,}out_of_memory: OS alloc failed, or fixed/reserved cap full
pub Arena :: struct { first: usize, head: usize, mode: u8,}first oldest chunk, head current bump chunk, mode an ARENA_* value
pub Mark :: struct { chunk: usize, used: usize,}saved bump position for restore
pub make :: fn() -> Arenareserves nothing until the first alloc
reserve
Section titled “reserve”pub reserve :: fn(max: usize) -> Arenamax bytes of address space, committed lazily; pointers never move
pub fixed :: fn(buf: []u8) -> Arenano syscalls, can’t grow; buf must outlive the arena
alloc_bytes
Section titled “alloc_bytes”pub alloc_bytes :: fn(self: *Arena, n: usize) -> []u8aborts on exhaustion
try_alloc_bytes
Section titled “try_alloc_bytes”pub try_alloc_bytes :: fn(self: *Arena, n: usize) -> []u8 ! MemError.out_of_memory instead of aborting
pub alloc :: fn($T: type, self: *Arena, n: usize) -> []T16-byte aligned; aborts on exhaustion
try_alloc
Section titled “try_alloc”pub try_alloc :: fn($T: type, self: *Arena, n: usize) -> []T ! MemErrorfallible alloc
alloc_one
Section titled “alloc_one”pub alloc_one :: fn($T: type, self: *Arena) -> *Taborts on exhaustion
pub dupe :: fn($T: type, self: *Arena, src: []const T) -> []Tcopy into the arena; aborts on exhaustion
pub new :: fn($T: type, self: *Arena) -> *Tzone spellings of alloc_one / alloc
new_slice
Section titled “new_slice”pub new_slice :: fn($T: type, self: *Arena, n: usize) -> []Tpub reset :: fn(self: *Arena)rewind, keep chunks, O(1); everything allocated before is invalid
pub mark :: fn(self: *Arena) -> Markfor restore; invalid after the next reset/deinit
restore
Section titled “restore”pub restore :: fn(self: *Arena, m: Mark)frees everything since m for reuse; chunks are kept
deinit
Section titled “deinit”pub deinit :: fn(self: *Arena)memory back to the OS (fixed: just cleared); reusable after