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 › resize
resize
BrkAllocator.resize
fn resize (
ctx : *anyopaque ,
buf : []u8 ,
alignment : Alignment ,
new_len : usize ,
return_address : usize ,
) bool
File
Code
fn resize (
ctx : *anyopaque ,
buf : []u8 ,
alignment : Alignment ,
new_len : usize ,
return_address : usize ,
) bool {
_ = ctx ;
_ = return_address ;
// 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 ;
}
}