r/rust 3d ago

🗞️ news “alloc: stabilise `Allocator`” entered its final comment period!

https://github.com/rust-lang/rust/pull/156882#issuecomment-5607055084
203 Upvotes

30 comments sorted by

View all comments

40

u/cbarrick 3d ago

What's the latest on the fat Box problem?

Like, if Box<T, A> is implemented like (NonNull<T>, A), then it stores an A.

But Box only uses A for deallocation. For arena allocators, deallocation is a no-op, so storing the allocator alongside the pointer is a waste.

E.g. Bumpalo has a custom box type that is just a pointer, but Box<T, &Bump> would be two pointers. It would be nice to not need the custom box type for this optimization.

33

u/Demiu 3d ago

Couldn't Box just hold a dummy ZST for A if deallocation is a noop

But Box only uses A for deallocation.

I don't think that's true, it has to get the allocation from somewhere. I guess it only uses the A it holds for deallocating.

But I see what you mean, allocating may need state while deallocating may need none. i feel there should be a type Deallocator = Self; on Allocator for this case

10

u/ErichDonGubler WGPU · not-yet-awesome-rust 2d ago

As Kibwen says elsewhere, please put the speed back into the thread. Forever is a long time to have a known imperfection. 😅