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 › BrkAllocator › resize Private Function resize Doc Source Private Function std.heap.BrkAllocator.resize
fn resize (
ctx : *anyopaque ,
buf : []u8 ,
alignment : Alignment ,
new_len : usize ,
return_address : usize ,
) bool Params ctx : *anyopaque buf : []u8 alignment : Alignment new_len : usize return_address : usize File heap/BrkAllocator.zig: 86
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 fn resize (
ctx : *anyopaque ,
buf : []u8 ,
alignment : Alignment ,
new_len : usize ,
return_address : usize ,
) bool {
_ = ctx ;
_ = return_address ;
// We don't want to move anything from one size class to another, but we
// can recover bytes in between powers of two.
const buf_align = alignment .toByteUnits ();
const old_actual_len = @max (buf .len + @sizeOf (usize ), buf_align );
const new_actual_len = @max (new_len +| @sizeOf (usize ), buf_align );
const old_small_slot_size = math .ceilPowerOfTwoAssert (usize , old_actual_len );
const old_small_class = math .log2 (old_small_slot_size ) - min_class ;
if (old_small_class < size_class_count ) {
const new_small_slot_size = math .ceilPowerOfTwo (usize , new_actual_len ) catch return false ;
return old_small_slot_size == new_small_slot_size ;
} else {
const old_bigpages_needed = bigPagesNeeded (old_actual_len );
const old_big_slot_pages = math .ceilPowerOfTwoAssert (usize , old_bigpages_needed );
const new_bigpages_needed = bigPagesNeeded (new_actual_len );
const new_big_slot_pages = math .ceilPowerOfTwo (usize , new_bigpages_needed ) catch return false ;
return old_big_slot_pages == new_big_slot_pages ;
}
}