Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › heap/ › FixedBufferAllocator.zig › alloc
alloc
FixedBufferAllocator.alloc
pub fn alloc (ctx : *anyopaque , n : usize , alignment : mem .Alignment , ra : usize ) ?[*]u8
File
Code
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 ;
}