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 standard library.
std › heap › ArenaAllocator › free Private Function free Doc Source Private Function std.heap.ArenaAllocator.free
fn free (ctx : *anyopaque , memory : []u8 , alignment : Alignment , ret_addr : usize ) void Params ctx : *anyopaque memory : []u8 alignment : Alignment ret_addr : usize File heap/ArenaAllocator.zig: 608
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636 fn free (ctx : *anyopaque , memory : []u8 , alignment : Alignment , ret_addr : usize ) void {
const arena : *ArenaAllocator = @ptrCast (@alignCast (ctx ));
_ = alignment ;
_ = ret_addr ;
assert (memory .len > 0 );
const node = arena .loadFirstNode ().?;
const buf_ptr = @as ([*]u8 , @ptrCast (node )) + @sizeOf (Node );
const cur_end_index = @atomicLoad (usize , &node .end_index , .monotonic );
if (buf_ptr + cur_end_index != memory .ptr + memory .len ) {
// Not the most recent allocation; we cannot free it.
return ;
}
const new_end_index = cur_end_index - memory .len ;
assert (buf_ptr + new_end_index == memory .ptr );
_ = @cmpxchgStrong (
usize ,
&node .end_index ,
cur_end_index ,
new_end_index ,
.release , // release freed memory
.monotonic ,
);
}