Skip to content

Commit 0bd1f8b

Browse files
committed
update allocator setup
1 parent 0fda720 commit 0bd1f8b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main.zig

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,16 @@ pub fn findInPath(allocator: std.mem.Allocator, env_map: std.process.EnvMap, sub
243243
return null;
244244
}
245245

246+
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
247+
246248
pub fn main() !void {
247-
var general_purpose_allocator: std.heap.GeneralPurposeAllocator(.{}) = .{};
248-
defer _ = general_purpose_allocator.deinit();
249-
const gpa = general_purpose_allocator.allocator();
249+
const gpa, const is_debug = switch (builtin.mode) {
250+
.Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true },
251+
.ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false },
252+
};
253+
defer if (is_debug) {
254+
_ = debug_allocator.deinit();
255+
};
250256

251257
var env_map: std.process.EnvMap = loadEnv(gpa) catch std.process.EnvMap.init(gpa);
252258
defer env_map.deinit();

0 commit comments

Comments
 (0)