Module allocator
Memory allocation abstractions and global allocator interface.
Types
Type-erased dynamic allocator wrapping any CustomAllocator implementation.
Describes the size and alignment requirements for a memory allocation.
Fields
| Name | Type | Description |
|---|---|---|
size | usize | Size in bytes. |
alignment | usize | Alignment in bytes (must be a power of two). |
Memory allocation error variants.
Variants
| Variant | Fields | Description |
|---|---|---|
OutOfMemory | Allocator ran out of memory. | |
InvalidSize | Requested size is invalid (e.g., zero or too large). | |
InvalidAlignment | Requested alignment is not a power of two. | |
InvalidPointer | Pointer passed to dealloc/realloc is invalid. |
Traits / Modules
User-implementable memory allocator interface. Implement this trait to provide custom allocation strategies.
Methods
alloc : fn(self : *(Self), comptime(T) : Type, count : usize) -> Result(Option(*(T)), AllocError)Allocate memory for count items of type T.
Parameters
| Name | Type | Notes |
|---|---|---|
self | *(Self) | |
T | Type | comptime |
count | usize |
Returns: Result(Option(*(T)), AllocError)
alloc_zeroed : fn(self : *(Self), comptime(T) : Type, count : usize) -> Result(Option(*(T)), AllocError)Allocate zeroed memory for count items of type T.
Parameters
| Name | Type | Notes |
|---|---|---|
self | *(Self) | |
T | Type | comptime |
count | usize |
Returns: Result(Option(*(T)), AllocError)
alloc_aligned : fn(self : *(Self), comptime(T) : Type, count : usize, alignment : usize) -> Result(Option(*(T)), AllocError)Allocate aligned memory for count items of type T with the given alignment.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
self | *(Self) | ||
T | Type | comptime | |
count | usize | ||
alignment | usize | Alignment in bytes (must be a power of two). |
Returns: Result(Option(*(T)), AllocError)
realloc : fn(forall(comptime(T) : Type), self : *(Self), old_ptr : Option(*(T)), new_count : usize) -> Result(Option(*(T)), AllocError)Reallocate memory to new_count items, preserving existing data.
Parameters
| Name | Type | Notes |
|---|---|---|
self | *(Self) | |
old_ptr | Option(*(T)) | |
new_count | usize |
Returns: Result(Option(*(T)), AllocError)
dealloc : fn(forall(comptime(T) : Type), self : *(Self), ptr : *(T)) -> Result(unit, AllocError)Deallocate memory pointed to by ptr.
Parameters
| Name | Type | Notes |
|---|---|---|
self | *(Self) | |
ptr | *(T) |
Returns: Result(unit, AllocError)
Functions
Check if allocating count elements of type T would overflow usize.
Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
count | usize |
Returns: bool
Constants
The process-wide global allocator (mimalloc by default, falls back to libc).
Value: GlobalAllocator(malloc: __yo_malloc, calloc: __yo_calloc, realloc: __yo_realloc, free: __yo_free, aligned_alloc: __yo_aligned_alloc)