|
|
|
|
|
by 14113
28 days ago
|
|
Something can only live (exclusively) in the type system if everything about it can be reified away. It's the same trade-off as in polymorphic container types: Either the type is tracked at runtime (a-la Java), or the code is instantiated per-type (a-la C++). In the context of allocators, Zig essentially requires that the programmer perform per-allocator instantiation while writing the code. Odin does the opposite, and requires that the information is held by the allocated object. I am unfamiliar with Rust's approach, but it will be either via runtime tracking, or via instantiation. |
|
Kind of. In a few days when Rust 1.00 stabilizes the Allocator MVP you can make a Vec<Goose, MyAllocator> whereas today in stable rust you always get a Vec<Goose, Global> because A = Global by default.
But while it seems as though Vec<Goose, MyAllocator> and Vec<Donkey, MyAllocator> and Vec<u32, MyAllocator> and Vec<f64, MyAllocator> is going to generate 4x the allocator code in fact (and you will see a somewhat similar trick with some C++ implementations) Vec<T,A>'s allocation work lives not in Vec<T,A>, or even RawVec<T,A> but inside RawVecInner<A> which you will notice only cares about the allocator type!.