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 › c_allocator_impl › resize Private Function resize Doc Source Private Function std.heap.c_allocator_impl.resize
fn resize (
_ : *anyopaque ,
memory : []u8 ,
alignment : Alignment ,
new_len : usize ,
return_address : usize ,
) bool Params _ : *anyopaque memory : []u8 alignment : Alignment new_len : usize return_address : usize File heap.zig: 259
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287 fn resize (
_ : *anyopaque ,
memory : []u8 ,
alignment : Alignment ,
new_len : usize ,
return_address : usize ,
) bool {
_ = return_address ;
assert (new_len > 0 );
if (new_len <= memory .len ) {
return true ; // in-place shrink always works
}
const mallocSize = func : {
if (@TypeOf (c .malloc_size ) != void ) break :func c .malloc_size ;
if (@TypeOf (c .malloc_usable_size ) != void ) break :func c .malloc_usable_size ;
if (@TypeOf (c ._msize ) != void ) break :func c ._msize ;
return false ; // we don't know how much space is actually available
};
const usable_len : usize = switch (allocStrat (alignment )) {
.raw , .posix_memalign => mallocSize (memory .ptr ),
.manual_align => usable_len : {
const unaligned_ptr = manualAlignHeader (memory .ptr ).*;
const full_len = mallocSize (unaligned_ptr );
const padding = @intFromPtr (memory .ptr ) - @intFromPtr (unaligned_ptr );
break :usable_len full_len - padding ;
},
};
return new_len <= usable_len ;
}