The standard memory allocation interface.

Fields

ptr: *anyopaque,
vtable: *const VTable,

Types

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 type T and sets all the items to `undefine…

Allocates an array of n items of type T and sets all the items to undefined. Depending on the Allocator implementation, it may be required to call free once the memory is no longer needed, to avoid a resource leak. If the Allocator implementation is unknown, then correct code will call free 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 type T and sets the first n items to…

Allocates an array of n + 1 items of type T and sets the first n items to undefined and the last item to sentinel. Depending on the Allocator implementation, it may be required to call free once the memory is no longer needed, to avoid a resource leak. If the Allocator implementation is unknown, then correct code will call free 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 create(self: Allocator, comptime T: type) Error!*T

Returns a pointer to undefined memory. Call destroy with the result to free t…

Returns a pointer to undefined memory. Call destroy with the result to free the memory.

fn destroy(self: Allocator, ptr: anytype) void

ptr should be the return value of create, or otherwise have the same addres…

ptr should be the return value of create, or otherwise have the same address and alignment property.

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, see destroy.

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 as free 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.

Values

Log2Align
undefined

Error Sets