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, T : Type, count : usize) -> <enum:enum_yo_id_3070>Allocate memory for count items of type T.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
T | Type | comptime |
count | usize |
Returns: <enum:enum_yo_id_3070>
alloc_zeroed : fn(self : Self, T : Type, count : usize) -> <enum:enum_yo_id_3070>Allocate zeroed memory for count items of type T.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
T | Type | comptime |
count | usize |
Returns: <enum:enum_yo_id_3070>
alloc_aligned : fn(self : Self, T : Type, count : usize, alignment : usize) -> <enum:enum_yo_id_3070>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: <enum:enum_yo_id_3070>
realloc : fn(generic(T) self : Self, old_ptr : <enum:enum_yo_id_3068>, new_count : usize) -> <enum:enum_yo_id_3070>Reallocate memory to new_count items, preserving existing data.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
old_ptr | <enum:enum_yo_id_3068> | |
new_count | usize |
Returns: <enum:enum_yo_id_3070>
dealloc : fn(generic(T) self : Self, ptr : *(T)) -> <enum:enum_yo_id_3079>Deallocate memory pointed to by ptr.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
ptr | *(T) |
Returns: <enum:enum_yo_id_3079>
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: source_namespace_yo_id_3087(malloc: <unknown: fn(size : usize) -> <enum:enum_yo_id_3081>>, calloc: <unknown: fn(nmemb : usize, size : usize) -> <enum:enum_yo_id_3081>>, realloc: <unknown: fn(ptr : <enum:enum_yo_id_3081>, size : usize) -> <enum:enum_yo_id_3081>>, free: <unknown: fn(ptr : <enum:enum_yo_id_3081>) -> unit>, aligned_alloc: <unknown: fn(alignment : usize, size : usize) -> <enum:enum_yo_id_3081>>)