stdlib.alloc¶
Memory Allocation
Generated from
v0.60.1. 1 source files, 18 documented symbols.
alloc.xi¶
type Layout¶
Memory layout: byte size and alignment.
| Field | Type |
|---|---|
size |
Int |
align |
Int |
Derives: Eq, Clone
fn new(size: Int) -> Layout¶
Layout with the given size and natural (8-byte) alignment.
fn with_align(self: Self, align: Int) -> Layout¶
Same size with the given alignment.
fn padded_size(self: Self) -> Int¶
Size rounded up to a multiple of the alignment.
type AllocError¶
Allocation failure with a human-readable message.
| Field | Type |
|---|---|
message |
Str |
Derives: Clone
type GlobalAlloc¶
The process-global allocator (stateless handle).
| Field | Type |
|---|---|
fn global_alloc() -> GlobalAlloc¶
Returns the concrete GlobalAlloc (the Allocator interface is a bound for generic code, not a value type the checker can return).
fn allocate(self: Self, layout: Layout) -> Result[*UInt8, AllocError]¶
Allocate
layout.sizebytes; Err on failure.
- Precondition:
layout.size > 0 - Postcondition:
result is Ok(_) => result != null
fn deallocate(self: Self, ptr: *UInt8, layout: Layout)¶
Free a block previously returned by
allocate.
- Precondition:
ptr != null
fn allocate_zeroed(self: Self, layout: Layout) -> Result[*UInt8, AllocError]¶
Allocate zeroed memory for
layout; Err on failure.
- Precondition:
layout.size > 0 - Postcondition:
result is Ok(_) => result != null
fn grow(self: Self, ptr: *UInt8, old: Layout, new: Layout) -> Result[*UInt8, AllocError]¶
Grow an allocation in place or by copy; Err on failure.
- Precondition:
ptr != null - Precondition:
new.size > old.size
fn shrink(self: Self, ptr: *UInt8, old: Layout, new: Layout) -> Result[*UInt8, AllocError]¶
Shrink an allocation in place or by copy; Err on failure.
- Precondition:
ptr != null - Precondition:
new.size < old.size - Precondition:
new.size > 0
fn alloc(size: Int) -> *UInt8¶
Global allocator (wraps malloc/free)
- Precondition:
size > 0 - Postcondition:
result != null
fn alloc_zeroed(size: Int) -> *UInt8¶
Allocate
sizezeroed bytes (8-byte aligned); null on failure.
- Precondition:
size > 0 - Postcondition:
result != null
fn realloc_sized(ptr: *UInt8, old_size: Int, new_size: Int) -> *UInt8¶
Resize an allocation. Named realloc_sized to avoid shadowing the C ABI symbol
realloc-- a same-named wrapper would collide with the extern declaration and be silently dropped from codegen.
- Precondition:
ptr != null - Precondition:
new_size > 0 - Postcondition:
result != null
fn dealloc(ptr: *UInt8, size: Int)¶
Free a block of
sizebytes.
- Precondition:
ptr != null
fn alloc_layout(layout: Layout) -> *UInt8¶
Sized allocation
- Precondition:
layout.size > 0 - Postcondition:
result != null
fn dealloc_layout(ptr: *UInt8, layout: Layout)¶
Free a block allocated with
layout.
- Precondition:
ptr != null