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
manualAlignHeader
Private Function
std.heap.c_allocator_impl.manualAlignHeader
fnmanualAlignHeader(aligned_ptr: [*]u8) *[*]u8
If allocStrat(a) == .manual_align, an allocation looks like this:
unaligned_ptr hdr_ptr aligned_ptr v v v +---------------+--------+--------------+
aligned_ptr is computed by aligning unaligned_ptr forward; it is what alloc returns.
hdr_ptr points to a pointer-sized header directly before the usable space. This header contains the value unaligned_ptr, so that we can pass it to free later. This is necessary because the width of the padding is unknown.
This function accepts aligned_ptr and offsets it backwards to return hdr_ptr.
If
allocStrat(a) == .manual_align, an allocation looks like this:unaligned_ptr hdr_ptr aligned_ptr v v v +---------------+--------+--------------+
+---------------+--------+--------------+
unaligned_ptris the raw return value ofmalloc.aligned_ptris computed by aligningunaligned_ptrforward; it is whatallocreturns.hdr_ptrpoints to a pointer-sized header directly before the usable space. This header contains the valueunaligned_ptr, so that we can pass it tofreelater. This is necessary because the width of the padding is unknown.This function accepts
aligned_ptrand offsets it backwards to returnhdr_ptr.