3 ms·
Right. The "will this or won't this allocate" analysis also needs to take into account all values being used by the code because they might be using allocators
by Arnavion 3y ago
Right. The "will this or won't this allocate" analysis also needs to take into account all values being used by the code because they might be using allocators internally.
I haven't written zig code in a few years so I don't know if people have developed a convention for it. That said, there is a reason types like `ArrayListUnmanaged` exist. If you have some complex type with a bunch of different collections as fields, you probably want to use the same allocator for all of those collections, so there's no reason to have the collections themselves store redundant copies of the allocator. Instead you can have the allocator held by the top-level type and use the `Unmanaged` collections as fields. This also means that you do end up needing to reference `self.allocator` explicitly when calling `.append()` etc, satisfying the original claim of TFA.