Closed Amanieu closed 4 years ago
In https://github.com/rust-lang/rust/pull/69824 you can see, how nice growing and shrinking can be separated :+1:
As AllocRef
will support zero-sized layouts, we have to decide, if we want restrictions on grow
and shrink
if a parameter is zero. I think it's fine to leave this to the implementor of AllocRef
and only require, that every pointer returned by any method of AllocRef
can be passed to another method.
Additionally, we should reevaluate #5.
I think grow
and shrink
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.
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 ofrealloc
, 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
andrealloc_zeroed
and add three new methods:grow
grow_zeroed
shrink