Just a quick question: should allocators be passed in as a value or as a pointer? My understanding is that parameters passed in as a pointer are meant to be mutated, whereas parameters passed in as a value are meant to be untouched. Underneath, zig will decide whether the value is passed as a copied value or as a reference, but we don’t get to control that.
What’s the convention for passing in allocators? I find myself flipping back and forth as I’m passing allocators deeper into a composition of structs.
The allocator interface is very lightweight and it only has two pointer member variables:
// The type erased pointer to the allocator implementation
ptr: *anyopaque,
vtable: *const VTable,
Generally speaking, passing lightweight structures (such as this and slices) is done by value.
Note that the allocator implementation is pointed to by the allocator interface. You’re only copying a pointer to the actual implementation and a pointer to the virtual table.