The standard memory allocation interface.
Functions
fn alignedAlloc(self: Allocator, comptime T: type, comptime alignment: ?u29, n: usize) Error![]align(alignment orelse @alignOf(T)) T
No documentation provided.
fn alloc(self: Allocator, comptime T: type, n: usize) Error![]T
Allocates an array of
n
items of typeT
and sets all the items to `undefine…Allocates an array of
n
items of typeT
and sets all the items toundefined
. Depending on the Allocator implementation, it may be required to callfree
once the memory is no longer needed, to avoid a resource leak. If theAllocator
implementation is unknown, then correct code will callfree
when done.For allocating a single item, see
create
.inline fn allocAdvancedWithRetAddr(self: Allocator, comptime T: type, comptime alignment: ?u29, n: usize, return_address: usize) Error![]align(alignment orelse @alignOf(T)) T
No documentation provided.
fn allocSentinel(self: Allocator, comptime Elem: type, n: usize, comptime sentinel: Elem) Error![:sentinel]Elem
Allocates an array of
n + 1
items of typeT
and sets the firstn
items to…Allocates an array of
n + 1
items of typeT
and sets the firstn
items toundefined
and the last item tosentinel
. Depending on the Allocator implementation, it may be required to callfree
once the memory is no longer needed, to avoid a resource leak. If theAllocator
implementation is unknown, then correct code will callfree
when done.For allocating a single item, see
create
.fn allocWithOptions(self: Allocator, comptime Elem: type, n: usize, comptime optional_alignment: ?u29, comptime optional_sentinel: ?Elem) Error!AllocWithOptionsPayload(Elem, optional_alignment, optional_sentinel)
No documentation provided.
fn allocWithOptionsRetAddr(self: Allocator, comptime Elem: type, n: usize, comptime optional_alignment: ?u29, comptime optional_sentinel: ?Elem, return_address: usize) Error!AllocWithOptionsPayload(Elem, optional_alignment, optional_sentinel)
No documentation provided.
fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T
Copies
m
to newly allocated memory. Caller owns the memory.fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T
Copies
m
to newly allocated memory, with a null-terminated element. Caller own…Copies
m
to newly allocated memory, with a null-terminated element. Caller owns the memory.fn free(self: Allocator, memory: anytype) void
Free an array allocated with
alloc
. To free a single item, seedestroy
.fn noFree(self: *anyopaque, buf: []u8, log2_buf_align: u8, ret_addr: usize) void
No documentation provided.
fn noResize(self: *anyopaque, buf: []u8, log2_buf_align: u8, new_len: usize, ret_addr: usize) bool
No documentation provided.
inline fn rawAlloc(self: Allocator, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8
This function is not intended to be called except from within the implementatio…
This function is not intended to be called except from within the implementation of an Allocator
inline fn rawFree(self: Allocator, buf: []u8, log2_buf_align: u8, ret_addr: usize) void
This function is not intended to be called except from within the implementatio…
This function is not intended to be called except from within the implementation of an Allocator
inline fn rawResize(self: Allocator, buf: []u8, log2_buf_align: u8, new_len: usize, ret_addr: usize) bool
This function is not intended to be called except from within the implementatio…
This function is not intended to be called except from within the implementation of an Allocator
fn realloc(self: Allocator, old_mem: anytype, new_n: usize) t: { const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; break :t Error![]align(Slice.alignment) Slice.child; }
This function requests a new byte size for an existing allocation, which can be…
This function requests a new byte size for an existing allocation, which can be larger, smaller, or the same size as the old memory allocation. If
new_n
is 0, this is the same asfree
and it always succeeds.fn reallocAdvanced(self: Allocator, old_mem: anytype, new_n: usize, return_address: usize) t: { const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; break :t Error![]align(Slice.alignment) Slice.child; }
No documentation provided.
fn resize(self: Allocator, old_mem: anytype, new_n: usize) bool
Requests to modify the size of an allocation. It is guaranteed to not move the …
Requests to modify the size of an allocation. It is guaranteed to not move the pointer, however the allocator implementation may refuse the resize request by returning
false
.