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 › testAllocatorAligned Public Function testAllocatorAligned Doc Source Public Function std.heap.testAllocatorAligned
pub fn testAllocatorAligned (base_allocator : mem .Allocator ) !void Params base_allocator : mem .Allocator File heap.zig: 479
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504 pub fn testAllocatorAligned (base_allocator : mem .Allocator ) !void {
var validationAllocator = mem .validationWrap (base_allocator );
const allocator = validationAllocator .allocator ();
// Test a few alignment values, smaller and bigger than the type's one
inline for ([_ ]Alignment { .@"1" , .@"2" , .@"4" , .@"8" , .@"16" , .@"32" , .@"64" }) |alignment | {
// initial
var slice = try allocator .alignedAlloc (u8 , alignment , 10 );
try testing .expect (slice .len == 10 );
// grow
slice = try allocator .realloc (slice , 100 );
try testing .expect (slice .len == 100 );
if (allocator .resize (slice , 10 )) {
slice = slice [0 ..10 ];
}
try testing .expect (allocator .resize (slice , 0 ));
slice = slice [0 ..0 ];
// realloc from zero
slice = try allocator .realloc (slice , 100 );
try testing .expect (slice .len == 100 );
if (allocator .resize (slice , 10 )) {
slice = slice [0 ..10 ];
}
try testing .expect (allocator .resize (slice , 0 ));
}
}