Description
This is a short-term potentially stabilizable incremental improvement on the status quo.
There's at least two benefits to doing this:
- Defining a
realloc
that takesLayout
will allow it to benefit from Enforce that layout size fits in isize in Layout rust#95295 - Over-aligned
Vec<u8>
can potentially be converted intoVec<u16>
without violating the requirement of dealloc with the correct alignment by a layout-changingrealloc
This would probably take the shape of unsafe fn grow(&self, ptr: *mut u8, old_layout: Layout, new_layout: Layout) -> *mut u8 { ... }
and shrink
for GlobalAlloc
along with the plumbing to see that through. These should probably be defaulted to call realloc
where possible to avoid pessimization of old GlobalAlloc
implementers.
Alternatively to providing the grow
/shrink
split on GlobalAlloc
, some alternative symbol to realloc
could be used which still allows both grow and shrink. C-inspired bad idea: realloc_s
😛 but resize
might be fine. realloc
will still exist (maybe deprecated) to point at resize
as the improved alternative.