▲ 4 r/Zig
const std = @import("std");
const Thing = struct {
// stuff
};
// This exists until the program ends
var things: []Thing = undefined;
// gpa_allocator is for temporary allocations and arena_allocator deinits when the program ends
pub fn init(gpa_allocator: std.mem.Allocator, arena_allocator: std.mem.Allocator) !void {
var loading_things = std.ArrayList(Thing).empty;
while (something) {
// something
loading_things.append(???_allocator, something);
}
// Now:
// things = try loading_things.toOwnedSlice(???_allocator);
// or
// things = loading_things.items;
// or maybe something else?
}
^Btw, ^I ^deleted ^my ^last ^post ^because ^I ^had ^a ^mistake ^in ^the ^code ^(not ^just ^the ^funny ^word) ^and ^it ^caused ^people ^not ^to ^understand ^what ^I ^wanted.
u/Blayung — 17 days ago