DoxigAlpha

Function parameters

Parameters

#
ctx:*anyopaque
n:usize
alignment:mem.Alignment
ra:usize

Functions in this namespace

Functions

#
allocator
Using this at the same time as the interface returned by `threadSafeAllocator` is not thread safe.
threadSafeAllocator
Provides a lock free thread safe `Allocator` interface to the underlying `FixedBufferAllocator`
isLastAllocation
This has false negatives when the last allocation had an

Source

Implementation

#
pub fn alloc(ctx: *anyopaque, n: usize, alignment: mem.Alignment, ra: usize) ?[*]u8 {
    const self: *FixedBufferAllocator = @ptrCast(@alignCast(ctx));
    _ = ra;
    const ptr_align = alignment.toByteUnits();
    const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse return null;
    const adjusted_index = self.end_index + adjust_off;
    const new_end_index = adjusted_index + n;
    if (new_end_index > self.buffer.len) return null;
    self.end_index = new_end_index;
    return self.buffer.ptr + adjusted_index;
}