Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 583
einpoklum Avatar asked Aug 16 '18 12:08

einpoklum


1 Answers

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() :-)

like image 179
Geezer Avatar answered Nov 18 '22 03:11

Geezer