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 › debug_allocator › DebugAllocator › detectLeaksInBucket Private Function detectLeaksInBucket Doc Source Private Function std.heap.debug_allocator.DebugAllocator.detectLeaksInBucket
fn detectLeaksInBucket (
bucket : *BucketHeader ,
size_class_index : usize ,
used_bits_count : usize ,
) usize Params bucket : *BucketHeader size_class_index : usize used_bits_count : usize File heap/debug_allocator.zig: 405
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437 fn detectLeaksInBucket (
bucket : *BucketHeader ,
size_class_index : usize ,
used_bits_count : usize ,
) usize {
const size_class = @as (usize , 1 ) << @as (Log2USize , @intCast (size_class_index ));
const slot_count = slot_counts [size_class_index ];
var leaks : usize = 0 ;
for (0 ..used_bits_count ) |used_bits_byte | {
const used_int = bucket .usedBits (used_bits_byte ).*;
if (used_int != 0 ) {
for (0 ..@bitSizeOf (usize )) |bit_index_usize | {
const bit_index : Log2USize = @intCast (bit_index_usize );
const is_used = @as (u1 , @truncate (used_int >> bit_index )) != 0 ;
if (is_used ) {
const slot_index : SlotIndex = @intCast (used_bits_byte * @bitSizeOf (usize ) + bit_index );
const stack_trace = bucketStackTrace (bucket , slot_count , slot_index , .alloc );
const page_addr = @intFromPtr (bucket ) & ~(page_size - 1 );
const addr = page_addr + slot_index * size_class ;
log .err ("memory address 0x{x} leaked: {f}" , .{
addr ,
std .debug .FormatStackTrace {
.stack_trace = stack_trace ,
.terminal_mode = std .log .terminalMode (),
},
});
leaks += 1 ;
}
}
}
}
return leaks ;
}