Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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
fn manualAlignHeader(aligned_ptr: [*]u8) *[*]u8

If allocStrat(a) == .manual_align, an allocation looks like this:

unaligned_ptr hdr_ptr aligned_ptr v v v +---------------+--------+--------------+

padding header usable bytes

+---------------+--------+--------------+

  • unaligned_ptr is the raw return value of malloc.
  • 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.

Params

  • aligned_ptr: [*]u8

File

heap.zig:202
202
203
204
    fn manualAlignHeader(aligned_ptr: [*]u8) *[*]u8 {
        return @ptrCast(@alignCast(aligned_ptr - @sizeOf(usize)));
    }