MSVC has its own non-standard functions _aligned_malloc, _aligned_realloc and _aligned_free.
C++17 and C11 have introduced (std::)aligned_alloc, results of which can be deallocated with free or realloc. But realloc cannot be used to actually reallocate memory returned by aligned_alloc, since it does not take an alignment parameter and thus cannot guarantee that the returned pointer will be properly aligned.
I can't even find any non-standard extensions that could reallocate aligned memory (preserving its alignment) on platforms other than Microsoft Windows / Visual C++.
Am I searching for it wrong, or is there indeed no _aligned_realloc alternative on POSIX and other platforms?
If so,
- Why?
- What can be used instead on those platforms? Is there nothing better than calling
aligned_allocwith the new alignment, and then doingmemcpyandfreeing the old pointer on success?