Zig: ArrayList
The documentation describes it as a contiguous, growable list of items in memory. This is a wrapper around a slice
of T values. The same allocator must be used throughout its entire lifetime. Initialize directly with empty or initCapacity, and deinitialize with deinit or toOwnedSlice.
Here is a quick look at how to use it:
const std = @import("std");
const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList;
pub fn main(init: std.process.Init) !void {
try showroom(init.gpa);
}
fn showroom(gpa: Allocator) !void {
var list: ArrayList(u8) = .empty;
defer list.deinit(gpa);
try list.append(gpa, 1);
try list.append(gpa, 2);
try list.append(gpa, 3);
for (list.items) |u| {
std.debug.print("value: {d}\n", .{u});
}
while (true) {
const u = list.pop() orelse break;
std.debug.print("popped value: {d}\n", .{u});
}
}