From 43d6a77c4ca18941b6afab065911a0b83563c6fa Mon Sep 17 00:00:00 2001 From: Nathan Franck Date: Tue, 8 Aug 2023 09:37:08 -0600 Subject: [PATCH] zig binarytrees: use ArenaAllocator --- bench/algorithm/binarytrees/1.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bench/algorithm/binarytrees/1.zig b/bench/algorithm/binarytrees/1.zig index 0aa87e7e..c79f8d95 100644 --- a/bench/algorithm/binarytrees/1.zig +++ b/bench/algorithm/binarytrees/1.zig @@ -7,16 +7,21 @@ const MIN_DEPTH = 4; const global_allocator = std.heap.c_allocator; pub fn main() !void { + var arena = std.heap.ArenaAllocator.init(global_allocator); + defer arena.deinit(); + + var allocator = arena.allocator(); + const stdout = std.io.getStdOut().writer(); const n = try get_n(); const max_depth = @max(MIN_DEPTH + 2, n); { const stretch_depth = max_depth + 1; - const stretch_tree = Node.make(stretch_depth, global_allocator).?; + const stretch_tree = Node.make(stretch_depth, allocator).?; defer stretch_tree.deinit(); try stdout.print("stretch tree of depth {d}\t check: {d}\n", .{ stretch_depth, stretch_tree.check() }); } - const long_lived_tree = Node.make(max_depth, global_allocator).?; + const long_lived_tree = Node.make(max_depth, allocator).?; defer long_lived_tree.deinit(); var depth: usize = MIN_DEPTH; @@ -25,7 +30,7 @@ pub fn main() !void { var sum: usize = 0; var i: usize = 0; while (i < iterations) : (i += 1) { - const tree = Node.make(depth, global_allocator).?; + const tree = Node.make(depth, allocator).?; defer tree.deinit(); sum += tree.check(); }