Why "bring your own allocator" APIs are not more popular in Rust?

I think that the storage type itself must in some way precisely encode which allocator is used. A heap storage would likely have to look like this.

struct AllocatorStorage<T, A> {
    ptr: *const T,
    len: usize,
    allocator: A // Might be a zero sized object
}

impl<T: Sized, A: Allocator> Storage for AllocatorStorage<T, A> {
    // ommited
}

If we somebody wants to do this range based allocator, this is in fact doable with Storages, but not with Allocators only. Just build your own storage, that knows how to drop itself.

Regarding drop: A Storage does never drop its content, nor does it provide direct access to its data. For a fixed size storage you could not use [T; N] but only something like [Slot<T>, N]. The Storage will be always be owned by the container type, which is responsible for dropping / moving out the stored data before releasing the storage itself.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.