Skip to content

Commit

Permalink
Use a passed allocator with Utilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makosai committed Aug 23, 2024
1 parent 0937454 commit e2f8466
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/Utils/Utilities.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const Constants = sustenet.utils.Constants;
/// Potential memory leak.
///
/// TODO: Fix this function.
pub fn splitByPascalCase(t: []const u8) ![]const u8 {
const allocator = std.heap.page_allocator;
pub fn splitByPascalCase(t: []const u8, allocator: std.mem.Allocator) ![]const u8 {
var list = std.ArrayList(u8).init(allocator);
defer list.deinit();

Expand All @@ -31,14 +30,14 @@ pub fn splitByPascalCase(t: []const u8) ![]const u8 {
return list.toOwnedSlice();
}

pub fn formatWithCommas(value: comptime_int) ![]const u8 {
pub fn formatWithCommas(value: comptime_int, allocator: std.mem.Allocator) ![]const u8 {
var buffer: [32]u8 = undefined; // Adjust size as needed
var fba = std.io.fixedBufferStream(&buffer);
var writer = fba.writer();
try writer.print("{d}", .{value});
const str = writer.context.getWritten();

var result = std.ArrayList(u8).init(std.heap.page_allocator);
var result = std.ArrayList(u8).init(allocator);
defer result.deinit();

var count: i32 = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test "create server(s) with gp_allocator" {
const allocator = gpa.allocator();

const n = 1;
const fmn = try sustenet.utils.Utilities.formatWithCommas(n);
const fmn = try sustenet.utils.Utilities.formatWithCommas(n, allocator);

print("Creating {s} servers...\n", .{fmn});

Expand Down

0 comments on commit e2f8466

Please sign in to comment.