Function alloc [src]

Prototype

pub fn alloc(ctx: *anyopaque, n: usize, alignment: mem.Alignment, ra: usize) ?[*]u8

Parameters

ctx: *anyopaquen: usizealignment: mem.Alignmentra: usize

Source

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; }