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/ › BrkAllocator.zig › free
free
BrkAllocator.free
fn free (
ctx : *anyopaque ,
buf : []u8 ,
alignment : Alignment ,
return_address : usize ,
) void
File
Code
fn free (
ctx : *anyopaque ,
buf : []u8 ,
alignment : Alignment ,
return_address : usize ,
) void {
_ = ctx ;
_ = return_address ;
const buf_align = alignment .toByteUnits ();
const actual_len = @max (buf .len + @sizeOf (usize ), buf_align );
const slot_size = math .ceilPowerOfTwoAssert (usize , actual_len );
const class = math .log2 (slot_size ) - min_class ;
const addr = @intFromPtr (buf .ptr );
if (class < size_class_count ) {
const node : *usize = @ptrFromInt (addr + (slot_size - @sizeOf (usize )));
node .* = global .frees [class ];
global .frees [class ] = addr ;
} else {
const bigpages_needed = bigPagesNeeded (actual_len );
const pow2_pages = math .ceilPowerOfTwoAssert (usize , bigpages_needed );
const big_slot_size_bytes = pow2_pages * bigpage_size ;
const node : *usize = @ptrFromInt (addr + (big_slot_size_bytes - @sizeOf (usize )));
const big_class = math .log2 (pow2_pages );
node .* = global .big_frees [big_class ];
global .big_frees [big_class ] = addr ;
}
}