Created
July 30, 2023 00:30
-
-
Save lmllrjr/b86f3ef8c8379a5d377e6dae517bb7ae to your computer and use it in GitHub Desktop.
use general purpose allocator for string concatenation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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