Skip to content

Instantly share code, notes, and snippets.

@lmllrjr
Created July 30, 2023 00:30
Show Gist options
  • Save lmllrjr/b86f3ef8c8379a5d377e6dae517bb7ae to your computer and use it in GitHub Desktop.
Save lmllrjr/b86f3ef8c8379a5d377e6dae517bb7ae to your computer and use it in GitHub Desktop.
use general purpose allocator for string concatenation
const std = @import("std");
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
pub fn main() !void {
var distance: i32 = 7857;
var str = std.fmt.allocPrint(
alloc,
"test alloc: {d}",
.{distance},
) catch "format failed";
defer alloc.free(str);
std.debug.print("{s}", .{str});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment