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
fnresize(ctx: *anyopaque, memory: []u8, alignment: Alignment, new_len: usize, ra: usize) bool {
assert(new_len != 0);
consts: *SafeAllocator = @ptrCast(@alignCast(ctx));
constf: *AllocFooter = .of(memory);
f.startModify(.resized, s, .{ .memory = memory, .alignment = alignment });
// Check that the allocation is not moving between a bucket and large allocation. This is// done after the above so that it is still checked that valid memory is passed and there// is no double modify.constfrom_large_alloc = s.isLarge(memory.len, alignment);
constto_large_alloc = s.isLargeOrOom(new_len, alignment) catch {
f.modify.setNone();
returnfalse;
};
if (from_large_alloc != to_large_alloc) {
@branchHint(.unlikely);
f.modify.setNone();
returnfalse;
}
if (from_large_alloc) {
@branchHint(.unlikely);
constentry = f.extended().container.large_entry;
constnew_alloc_len = AllocFooter.allocLenLarge(s, new_len);
if (!s.backing.rawResize(
memory.ptr[0..AllocFooter.allocLenLarge(s, memory.len)],
AllocFooter.allocAlign(alignment),
new_alloc_len,
ra,
)) {
f.modify.setNone();
returnfalse;
}
constnew_footer = AllocFooter.populate(
@alignCast(memory.ptr[0..new_alloc_len]),
new_len,
alignment,
ra,
true,
false,
.{ .large_entry = entry },
s,
);
assert(entry.kind == .large_alloc);
entry.* = .fromLargeAlloc(new_footer);
returntrue;
}
if (new_len < memory.len) {
// Resize shrinks are disallowed in all cases since the linked list would be broken. Even// if this footer is the final one, the fill value would need decreased which would allow// memory to be reused.f.modify.setNone();
returnfalse;
}
if (s.growingResizeBucket(f, memory, alignment, new_len, ra)) {
@branchHint(.likely);
returntrue;
} else {
f.modify.setNone();
returnfalse;
}
}