c++c++17memory-alignmentdynamic-allocationmemory-reallocation

What's the reallocation equivalent of std::aligned_alloc()?


I've noticed std::aligned_alloc() coming into C++17, and I like it. But - what happens when I need to reallocate? I can do this manually (assuming the available space at the currently-allocated address is just the amount of space I asked for), but shouldn't there be a facility for this in the standard library?


Solution

  • There isn't such standard call equivalent.

    Even more so, Microsoft's latest implementation of C++ still has its own _aligned_malloc() instead of the now standardized std::aligned_alloc(), and here they explain why:

    aligned_alloc() will probably never be implemented, as C11 specified it in a way that’s incompatible with our implementation (namely, that free() must be able to handle highly aligned allocations).

    Among their (Microsoft's) underscore-prefixed implementations they do serve you with _aligned_realloc() :-)