-
Notifications
You must be signed in to change notification settings - Fork 9
Closed
rust-lang/rust
#70362Labels
Description
If you think about it, growing and shrinking an allocation are actually 2 very different operations. The only reason for merging them together is historical, because C did it.
If you look at Vec
, the biggest user of realloc
, you will see that growing and shrinking are two completely separate code paths. Similarly, within allocator implementations, growing and shrinking are also often handled differently.
As such, it makes sense to remove realloc
and realloc_zeroed
and add three new methods:
grow
grow_zeroed
shrink
Lokathor and LesleyLaiTimDiekmann, Wodann and LesleyLai
Activity
AllocRef
onSystem
withoutGlobalAlloc
#43TimDiekmann commentedon Mar 8, 2020
In rust-lang/rust#69824 you can see, how nice growing and shrinking can be separated 👍
TimDiekmann commentedon Mar 9, 2020
As
AllocRef
will support zero-sized layouts, we have to decide, if we want restrictions ongrow
andshrink
if a parameter is zero. I think it's fine to leave this to the implementor ofAllocRef
and only require, that every pointer returned by any method ofAllocRef
can be passed to another method.Additionally, we should reevaluate #5.
Amanieu commentedon Mar 9, 2020
I think
grow
andshrink
should require that the new size is strictly greater than or less than the current size. Apart from that I don't think it makes sense to add restrictions.AllocRef
trait to match allocator-wg's latest consens rust-lang/rust#69889AllocRef
trait to match allocator-wg's latest consens; Take 2 rust-lang/rust#70362