From zig-dev
Reference for Zig 0.15+ ArrayList API which passes the allocator to each method call instead of at initialization. Use when working with ArrayLists in Zig 0.15+.
How this skill is triggered — by the user, by Claude, or both
Slash command
/zig-dev:zig-arraylistThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
This project uses Zig 0.15 which has a different ArrayList API than earlier versions.
This project uses Zig 0.15 which has a different ArrayList API than earlier versions.
Old (pre-0.15):
var list = std.ArrayList(T).init(allocator);
New (0.15+):
var list = std.ArrayList(T){};
The allocator is NOT passed at initialization. Instead, it's passed to each method call.
Append:
// Old
try list.append(item);
// New (0.15)
try list.append(allocator, item);
Deinit:
// Old
list.deinit();
// New (0.15)
list.deinit(allocator);
AppendSlice:
// Old
try list.appendSlice(items);
// New (0.15)
try list.appendSlice(allocator, items);
ToOwnedSlice:
// Old
const slice = try list.toOwnedSlice();
// New (0.15)
const slice = try list.toOwnedSlice(allocator);
const std = @import("std");
fn example(allocator: std.mem.Allocator) ![]u32 {
// Initialize without allocator
var list = std.ArrayList(u32){};
defer list.deinit(allocator);
// All operations take allocator as first arg
try list.append(allocator, 1);
try list.append(allocator, 2);
try list.append(allocator, 3);
// Convert to owned slice
return try list.toOwnedSlice(allocator);
}
Zig 0.15 moved to a more explicit allocator passing style. This makes it clearer where allocations happen and allows using different allocators for different operations on the same list.
If you see errors like:
struct 'array_list.Aligned(T,null)' has no member named 'init'expected 2 argument(s), found 1You're likely using the old API. Update to the new pattern shown above.
npx claudepluginhub code0100fun/botfiles --plugin zig-devProvides Zig 0.13-0.14 updates: breaking changes like DebugAllocator, unmanaged arrays, root_module build API; new features including labeled switches, decl literals, @branchHint. Use for Zig coding.
Guides Zig allocator selection, memory lifecycle management, leak debugging, and patterns like arena, page, and fixed-buffer allocation.
Guides Zig memory management and allocator selection. Covers arena, page, fixed-buffer allocators, memory lifecycle, and leak debugging.