Strings In Depth18 / 19
Up next

Concatenate with an allocator

const std = @import("std");

pub fn main() !void {
    const alloc = std.heap.page_allocator;
    const parts = [_][]const u8{ "foo", "bar", "baz" };
    // concat allocates one buffer holding every piece
    const joined = try std.mem.concat(alloc, u8, &parts);
    defer alloc.free(joined);
    std.debug.print("{s}\n", .{joined});
}
What you're solving

std.mem.concat joins slices onto the heap