An ever worked code doesnot work now

zig
const home_dir = findHomeDir();
if (home_dir) |hd| {
        var full_path = try std.ArrayList(u8).initCapacity(std.heap.page_allocator,256);
        defer full_path.deinit();

        SSQNUM = try std.fs.path.join(full_path.allocator, &.{hd, DATA_DIR, "ssqNum.txt"});
        SSQHITNUM = try std.fs.path.join(full_path.allocator, &.{hd, DATA_DIR, "ssqHitNum.txt"});
}
```
$zig version
0.15.1

$zig build-exe -O ReleaseSmall -fstrip ssq.zig

ssq.zig:37:49: error: no field named ‘allocator’ in struct ‘array_list.Aligned(u8,null)’
SSQNUM = try std.fs.path.join(full_path.allocator, &.{hd, DATA_DIR, “ssqNum.txt”});
^~~~~~~~~
/data/data/com.termux/files/usr/lib/zig/lib/std/array_list.zig:606:12: note: struct declared here
return struct {

Regards !

The default version of array list has gone from managed (stores its allocator) to unmanaged.

The managed variant is still available as std.array_list.Managed, but it is deprecated and will be removed.

Since the unmanaged version doesn’t store the allocator, you have to pass it to each function that requires it.

release notes

Also, I advise you don’t use page_allocator directly as it always asks the OS for a whole page even for tiny allocations. It is usually used behind other, smarter, allocators.
ArenaAllocator.init(page_allocator) is fine for most small programs. Also, DebugAllocator (renamed from GeneralPurposeAllocator) is great for preventing memory bugs, though it doesn’t eliminate them entirely.
There is also a new allocator std.heap.smp_allocator, this is very fast, so fast it competes with glibc’s.

4 Likes