3 ms·
The C++ Allocator concept has no reallocate() function, which would also have to change in order to actually see a speedup: https://en.cppreference.com/w/cpp/n
by nly 2y ago
The C++ Allocator concept has no reallocate() function, which would also have to change in order to actually see a speedup:
https://en.cppreference.com/w/cpp/named_req/Allocator https://en.cppreference.com/w/cpp/named_req/Allocator
But regardless, realloc() can't be used to implement the optimisation efficiently because of this line from the C man page:
> The realloc() function returns a pointer to the newly allocated memory, which is suitably aligned for any kind of variable *and may be different from ptr*
Basically, if the implementation can't extend the memory allocation it can fallback to malloc(), memcpy() and free() - so by the time C++ gets control back, it's too late to call the appropriate C++ functions.