Module std::alloc
Allocators over storage the program owns: FixedBuffer serves Alloc from a byte buffer
(no heap, usable in realtime code), and bump_alloc is the step to build your own bump
allocator handler.
Source: std/alloc.weir; committed interface: std/alloc.iface. Index
- fn
bump_alloc: One step of a bump allocator over the storage atbase: the first block ofl.sizebytes aligned tol.alignat or after offset*used, which it advances past the block. - handler
FixedBuffer: AnAllochandler that bumps throughbuf:with FixedBuffer(&mut bytes, 0) { … }serves every allocation in the block frombytes.
fn bump_alloc
pub fn bump_alloc<r>(base: Ptr<u8> in r, used: &mut usize, l: &Layout) -> Ptr<u8> in r
One step of a bump allocator over the storage at base: the first block of l.size bytes
aligned to l.align at or after offset *used, which it advances past the block.
It does not check the end of the storage: the caller keeps the block inside it (a block past
the end is reported out of range by the raw monitor) and turns it into a Mem with
mem_from_ptr(p, l.size).
Committed interface (std/alloc.iface):
writes through used: everything
handler FixedBuffer
pub handler FixedBuffer(mut buf: &mut [u8], mut used: usize) for Alloc with Process
An Alloc handler that bumps through buf: with FixedBuffer(&mut bytes, 0) { … } serves
every allocation in the block from bytes.
Allocation aborts the process (with Process) when the buffer is exhausted; free and
resize do nothing, so memory is reclaimed only when the buffer is. No heap is touched, so
it fits realtime code.
Handles Alloc, with clauses: