Skip to content

Commit

Permalink
use an arena for the args
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Feb 22, 2025
1 parent 85df280 commit 9519d3f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ pub const std_options = .{
};

pub fn main() !void {
var mem: [4096]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&mem);
const args = try parseArgs(fba.allocator());

if (args.mode == .help) {
// don't need to create a gpa in this case
return args.printUsageAndExit(args.mode.help);
}

// allocator
// - in Debug mode we use the General Purpose Allocator to detect memory leaks
// - in Release mode we use the c allocator
Expand All @@ -62,8 +53,12 @@ pub fn main() !void {
_ = gpa.detectLeaks();
};

var args_arena = std.heap.ArenaAllocator.init(alloc);
defer args_arena.deinit();
const args = try parseArgs(args_arena.allocator());

switch (args.mode) {
.help => unreachable, // handled above
.help => args.printUsageAndExit(args.mode.help),
.serve => |opts| {
const address = std.net.Address.parseIp4(opts.host, opts.port) catch |err| {
log.err("address (host:port) {any}\n", .{err});
Expand Down

0 comments on commit 9519d3f

Please sign in to comment.