Function testAllocatorAligned [src]

Prototype

pub fn testAllocatorAligned(base_allocator: mem.Allocator) !void

Parameters

base_allocator: mem.Allocator

Source

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 ([_]u29{ 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)); } }