testAllocatorAligned
Function parameters
Parameters
- base_allocator:mem.Allocator
Type definitions in this namespace
Types
- GeneralPurposeAllocatorConfig
- Deprecated; to be removed after 0.14.0 is tagged.
Functions in this namespace
Functions
- GeneralPurposeAllocator
- Deprecated; to be removed after 0.14.0 is tagged.
- pageSize
- If the page size is comptime-known, return value is comptime.
- defaultQueryPageSize
- The default implementation of `std.options.queryPageSize`.
- stackFallback
- Returns a `StackFallbackAllocator` allocating using either a
- StackFallbackAllocator
- An allocator that attempts to allocate using a
- testAllocator
- This one should not try alignments that exceed what C malloc can handle.
TODO Utilize this on Windows.
Values
- next_mmap_addr_hint
- TODO Utilize this on Windows.
- page_size_min
- comptime-known minimum page size of the target.
- page_size_max
- comptime-known maximum page size of the target.
- c_allocator
- Supports the full Allocator interface, including alignment, and exploiting
- raw_c_allocator
- Asserts allocations are within `@alignOf(std.c.max_align_t)` and directly
- page_allocator
- On operating systems that support memory mapping, this allocator makes a
- smp_allocator
- = .{ .ptr = undefined, .vtable = &SmpAllocator.vtable, }
- wasm_allocator
- This allocator is fast, small, and specific to WebAssembly.
Source
Implementation
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));
}
}