Why isn`t c++17`s std::aligned_alloc at all implemented? RRS feed

  • Question

  • When enabling the compiler to use c++17 and even std:c++latest the function std::aligned_alloc described is cpp reference(cant post the link, just mind that its different from the c11 version of aligned_malloc)

    is not defined, thus making the visual studio compiler and std library non-compliant with the c++17 standard. Would this mean we now have two different languages between c++ in visual studio and c++ in the rest compilers?

    Friday, July 17, 2020 11:50 PM

All replies

  • The reason is stated in the documentation:

    "MSVC doesn't support the aligned_alloc function. C11 specified aligned_alloc() in a way that's incompatible with the Microsoft implementation of free(), namely, that free() must be able to handle highly aligned allocations."

    Igor Tandetnik

    Saturday, July 18, 2020 12:31 AM
  • Also please look at the solution for this bug report about the same thing. A Microsoft employee explains what the exact problem is and that they are investigating this.

    So the C11 (yes, std::aligned_alloc is a C11 function, it is in the cstdlib compatibility header) definition of using free to deallocate doesn't work and as a work around another means was required.

    This is also the reason why using operator new to allocate over aligned memory requires you to directly call the placement operator delete function.

    If you want to try to speed this up, what you can do is go to the Visual Studio feedback (available at the top right corner of the Visual Studio window) and create a suggestion. Then get as many people as you can to upvote it.

    What's more, if you are on Windows 10, go to the feedback hub and add a suggestion there. Then get as many people as you can to upvote it. By doing this, you let Microsoft know that this is a feature that people really want.

    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Edited by Darran Rowe Saturday, July 18, 2020 6:51 PM
    Saturday, July 18, 2020 6:46 PM