2 ms·
How do you implement arena allocators in that situation? Or allocate from a fixed-size buffer? { var arena = std.heap.ArenaAllocator.init(std.heap.
by messe 4y ago
How do you implement arena allocators in that situation? Or allocate from a fixed-size buffer?
{
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit(); // All allocations made by the above allocator will be freed at the end of scope
const allocator = arena.allocator();
var i = 0;
while (i < 1000000) : (i += 1) {
_ = try allocator.create(i32);
}
// all allocations are freed
}
var buffer: [1000]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buffer);
const allocator = fba.allocator();
// the allocator will return an address inside of `buffer`
_ = try allocator.create([512]u8);