3 ms·
Zig stdlib "objects" like dynamic containers indeed usually only take the allocator during initialization and then store it in the instance. E.g. var list
by flohofwoe 3y ago
Zig stdlib "objects" like dynamic containers indeed usually only take the allocator during initialization and then store it in the instance. E.g.
var list = ArrayList(u8).init(test_allocator);
defer list.deinit();
try list.append('H');
try list.append('e');
...
- Cloudef 3y agoThere are also often Unmanaged variants where you pass allocator to every method. In these scenarios you have to make sure you use the same allocator though. Unmanaged can be useful for short lived allocations or type that combines many standard containers, saving memory.