My understanding of realloc was that, if memory was available contiguously beyond the point allocated, it can try to extend the current allocation without copying.
While reading this https://github.com/facebook/folly/blob/master/folly/docs/FBVector.md I came to know that most allocators avoid inplace reallocation
. Many memory allocators do not support in- place reallocation, although most of them could. This comes from the now notorious design of realloc() to opaquely perform either in-place reallocation or an allocate-memcpy-deallocate cycle. Such lack of control subsequently forced all clib-based allocator designs to avoid in-place reallocation, and that includes C++'s new and std:allocator.
As answered in another question (Why is there no reallocation functionality in C++ allocators?) about the lack of reallocators in C++ where the accepted answer mentions that such an allocator would have prohibited realloc use form C library but does not answer why not try to make realloc that expands the current memory if possible?
Why not make one? Actually, there are proposals to do exactly that:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With