
Christopher Jefferson wrote:
Thanks!
No offence, but while that method is good as it is as general as possible, it perhaps doesn't look very "C-like", and is maybe too complex to try to pursade them to add.
Yes, it's not a proposal, it was just what I needed to add to implement C++ features.
How important is backward expansion, and try_shrink_in_place? While obviously these things are useful, do you think they are "vital"? I'm interested as you have clearly written a lot of code which uses these mechanisms.
Shrink in place is quite useful, because it offers no-throw trimming for containers like vector.
My thought is that adding a function which is exactly "realloc, except don't move, just return", with the option to try to get as much memory as possible, say:
int realloc_try(void* ptr, size_t size, size_t* new_size)
With the same semantics as relloc except it doesn't move, and if it can do a partial expansion (or shrink) tries to do as much as it can and returns the new size in new_size, is (from looking at source) a very easy addition to many mallocs, and less invasive.
It's an alternative, the advantage of a possible allocation is that the internal mutex and memory algorithm security checks are performed only once.
Chris
Another note: containers that implement this also support stateful allocators so they can be used also for your proposed arena-like allocators. Best, Ion