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

Provide alignment-changing realloc on `GlobalAlloc` #102

Open CAD97 opened 2 years ago

CAD97 commented 2 years ago

This is a short-term potentially stabilizable incremental improvement on the status quo.

Zulip discussion

There's at least two benefits to doing this:

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.