2 ms·
Yeah, you'll have to add a method to whatever type you implement `Allocator` for that returns the size. When you call `Vec::push` or `HashMap::insert`, it'll a
by nynx 5y ago
Yeah, you'll have to add a method to whatever type you implement `Allocator` for that returns the size.
When you call `Vec::push` or `HashMap::insert`, it'll allocate on the heap if there isn't already capacity for it in the already allocated space. If the custom allocator you make just allocates one large space from the global allocator, then you can deallocate the whole thing at once in the `Drop` implementation.
There is limited documentation at the moment because the feature is still in flux, but take a look at `Vec::new_in` [0] to get an idea of how a collection can use an allocator.
[0]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.new_in https://doc.rust-lang.org/std/vec/struct.Vec.html#method.new...