rust-lang / wg-allocators

Home of the Allocators working group: Paving a path for a standard set of allocator traits to be used in collections!
http://bit.ly/hello-wg-allocators
203 stars 9 forks source link

Why does Allocator::{grow,grow_zeroed,shrink} take new_layout instead of just new_size? #95

Closed yanchith closed 2 years ago

yanchith commented 2 years ago

Hey all, a long time lurker here :) Recently I did a small bump allocator (like bumpalo, only much simpler) for a game project I am making, and I wondered about why does Allocator::{grow,grow_zeroed,shrink} take new_layout instead of just new_size.

This allows the caller to request a different-than-original alignment, and while the allocator is allowed to return AllocError if it doesn't want to deal with it, it still needs to at least check, if the alignment requirement didn't increase.

Since I can only imagine contrived uses of changing alignment on the fly, I'd be interested in what was the reasoning for the current design.

Amanieu commented 2 years ago

I think most of the history behind this design is covered in #5.

yanchith commented 2 years ago

Oh cool, thanks! Great to know that the additional branch will likely get optimized away. Closing.