Fix allocator scope.
This commit is contained in:
parent
21dfcb915e
commit
4bc6aac4e9
13
src/main.zig
13
src/main.zig
|
@ -50,16 +50,21 @@ pub fn log(
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
std.log.info(.main, "Starting Bar.", .{});
|
std.log.info(.main, "Starting Bar.", .{});
|
||||||
var allocator: *std.mem.Allocator = undefined;
|
var allocator: *std.mem.Allocator = undefined;
|
||||||
var dbgAlloc: *DebugAllocator = undefined;
|
var dbgAlloc: DebugAllocator = undefined;
|
||||||
|
var arena: std.heap.ArenaAllocator = undefined;
|
||||||
if (debug_allocator) {
|
if (debug_allocator) {
|
||||||
// Warning that DebugAllocator can get a little crashy.
|
// Warning that DebugAllocator can get a little crashy.
|
||||||
dbgAlloc = &DebugAllocator.init(std.heap.page_allocator, 8192 * 8192);
|
dbgAlloc = DebugAllocator.init(std.heap.page_allocator, 8192 * 8192);
|
||||||
allocator = &dbgAlloc.allocator;
|
allocator = &dbgAlloc.allocator;
|
||||||
} else {
|
} else {
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
defer arena.deinit();
|
|
||||||
allocator = &arena.allocator;
|
allocator = &arena.allocator;
|
||||||
}
|
}
|
||||||
|
defer {
|
||||||
|
if (!debug_allocator) arena.deinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var bar = barImpl.initBar(allocator);
|
var bar = barImpl.initBar(allocator);
|
||||||
var br = Bar.init(&bar);
|
var br = Bar.init(&bar);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue