mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
std.heap: test smp_allocator
This commit is contained in:
parent
51c4ffa410
commit
3d7c5cf64a
@ -481,7 +481,7 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
test "c_allocator" {
|
test c_allocator {
|
||||||
if (builtin.link_libc) {
|
if (builtin.link_libc) {
|
||||||
try testAllocator(c_allocator);
|
try testAllocator(c_allocator);
|
||||||
try testAllocatorAligned(c_allocator);
|
try testAllocatorAligned(c_allocator);
|
||||||
@ -490,12 +490,19 @@ test "c_allocator" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "raw_c_allocator" {
|
test raw_c_allocator {
|
||||||
if (builtin.link_libc) {
|
if (builtin.link_libc) {
|
||||||
try testAllocator(raw_c_allocator);
|
try testAllocator(raw_c_allocator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test smp_allocator {
|
||||||
|
try testAllocator(smp_allocator);
|
||||||
|
try testAllocatorAligned(smp_allocator);
|
||||||
|
try testAllocatorLargeAlignment(smp_allocator);
|
||||||
|
try testAllocatorAlignedShrink(smp_allocator);
|
||||||
|
}
|
||||||
|
|
||||||
test PageAllocator {
|
test PageAllocator {
|
||||||
const allocator = page_allocator;
|
const allocator = page_allocator;
|
||||||
try testAllocator(allocator);
|
try testAllocator(allocator);
|
||||||
|
|||||||
@ -241,48 +241,3 @@ fn slotSize(class: usize) usize {
|
|||||||
const Log2USize = std.math.Log2Int(usize);
|
const Log2USize = std.math.Log2Int(usize);
|
||||||
return @as(usize, 1) << @as(Log2USize, @intCast(class));
|
return @as(usize, 1) << @as(Log2USize, @intCast(class));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "large alloc, resize, remap, free" {
|
|
||||||
const gpa = std.heap.smp_allocator;
|
|
||||||
|
|
||||||
const ptr1 = try gpa.alloc(u64, 42768);
|
|
||||||
const ptr2 = try gpa.alloc(u64, 52768);
|
|
||||||
gpa.free(ptr1);
|
|
||||||
const ptr3 = try gpa.alloc(u64, 62768);
|
|
||||||
gpa.free(ptr3);
|
|
||||||
gpa.free(ptr2);
|
|
||||||
}
|
|
||||||
|
|
||||||
test "small allocations - free in same order" {
|
|
||||||
const gpa = std.heap.smp_allocator;
|
|
||||||
|
|
||||||
var list = std.ArrayList(*u64).init(std.testing.allocator);
|
|
||||||
defer list.deinit();
|
|
||||||
|
|
||||||
var i: usize = 0;
|
|
||||||
while (i < 513) : (i += 1) {
|
|
||||||
const ptr = try gpa.create(u64);
|
|
||||||
try list.append(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (list.items) |ptr| {
|
|
||||||
gpa.destroy(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
test "small allocations - free in reverse order" {
|
|
||||||
const gpa = std.heap.smp_allocator;
|
|
||||||
|
|
||||||
var list = std.ArrayList(*u64).init(std.testing.allocator);
|
|
||||||
defer list.deinit();
|
|
||||||
|
|
||||||
var i: usize = 0;
|
|
||||||
while (i < 513) : (i += 1) {
|
|
||||||
const ptr = try gpa.create(u64);
|
|
||||||
try list.append(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (list.popOrNull()) |ptr| {
|
|
||||||
gpa.destroy(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user