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. Private Function
fnremap(
ctx: *anyopaque,
memory: []u8,
alignment: Alignment,
new_len: usize,
return_address: usize,
) ?[*]u8 {
assert(new_len > 0);
// Prefer resizing in-place if possible, since `realloc` could be expensive even if legal.if (resize(ctx, memory, alignment, new_len, return_address)) {
returnmemory.ptr;
}
switch (allocStrat(alignment)) {
.raw => {
// `malloc` and friends guarantee the required alignment, so we can try `realloc`.// C only needs to respect `max_align_t` up to the allocation size due to object// alignment rules. If necessary, extend the allocation size.constactual_len = @max(new_len, @alignOf(std.c.max_align_t));
constnew_ptr = c.realloc(memory.ptr, actual_len) orelsereturnnull;
assert(alignment.check(@intFromPtr(new_ptr)));
return@ptrCast(new_ptr);
},
.posix_memalign, .manual_align => {
// `realloc` would potentially return a new allocation which does not respect// the original alignment, so we can't do anything more.returnnull;
},
}
}