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 › FixedBufferAllocator › resize Public Function resize Doc Source Public Function std.heap.FixedBufferAllocator.resize
pub fn resize (
ctx : *anyopaque ,
buf : []u8 ,
alignment : mem .Alignment ,
new_size : usize ,
return_address : usize ,
) bool Params ctx : *anyopaque buf : []u8 alignment : mem .Alignment new_size : usize return_address : usize File heap/FixedBufferAllocator.zig: 74
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 pub fn resize (
ctx : *anyopaque ,
buf : []u8 ,
alignment : mem .Alignment ,
new_size : usize ,
return_address : usize ,
) bool {
const self : *FixedBufferAllocator = @ptrCast (@alignCast (ctx ));
_ = alignment ;
_ = return_address ;
assert (@inComptime () or self .ownsSlice (buf ));
if (!self .isLastAllocation (buf )) {
if (new_size > buf .len ) return false ;
return true ;
}
if (new_size <= buf .len ) {
const sub = buf .len - new_size ;
self .end_index -= sub ;
return true ;
}
const add = new_size - buf .len ;
if (add + self .end_index > self .buffer .len ) return false ;
self .end_index += add ;
return true ;
}