Closed SimonSapin closed 4 years ago
If we also decide to lift the same-alignment restriction (which should be discussed separately, feel free to file a dedicated issue), then the signature becomes
old_layout: Layout, new_layout: Layout
and this issue is moot.
I like this option the most, as this may be valid for arbitrary allocators.
Alright, I’ve filed https://github.com/rust-lang/wg-allocators/issues/5 for that discussion.
https://github.com/rust-lang/wg-allocators/issues/5 is closed, and AllocRef
’s grow
and shrink
methods still take layout: Layout, new_size: usize
. Should they be changed to old_size: usize, new_layout: Layout
?
I find it confusing when the new_
parameter gets an alignment, but that has to match the alignment of the old layout. Surely it is more convenient when one already has the layout passed to the method, but that Layout
also has to be constructed beforehand.
As the AllocRef
trait changed a lot since this issue was opend, I opened #69 and closing this in favor of the linked issue.
The
GlobalAlloc
trait is stable with this method:(And similarly the
std::alloc::realloc
function.)Note
new_size: usize
instead ofnew_layout: Layout
. This is because this method does not support changing the alignment.When (re)allocation fails (when the method returns
null
), the caller typically wants to callhandle_alloc_error
which takes aLayout
. This value needs to be created with code likeLayout::from_size_align(new_size, layout.align()).unwrap()
. It would be better if the value passed to the error handler was already available. This would be the case if the parameters torealloc
wereold_size: usize, new_layout: Layout
instead.For the
Alloc
trait, we could:GlobalAlloc
, orold_size: usize, new_layout: Layout
, orold_layout: Layout, new_layout: Layout
and this issue is moot.