Skip to content

std::aligned_alloc() and ms-windows

Nicolas Marsic requested to merge win32Aligned into master

Dear all,

The current gmshfem does not compile with mingw. One reason is that std::aligned_alloc() is apparently not compatible with ms-windows internals [1]! The problem seems to affect msvc[1, 2] as well.

One bypass is to call _aligned_malloc() and _aligned_free() [3]. That works with mingw (tested) and apparently with msvc >= 2015 (untested).

In its current form, the merge request replaces the std::aligned_alloc() calls with a macro. This macro is _aligned_malloc() with a win32 compiler and std::aligned_alloc() otherwise. The same goes for free().

One could also do it at runtime, but I don't know how critical function/executionTree/FunctionAllocator.cpp is.

By the way, the CMakeLists manipulates WIN32, but that's an internal variable of cmake [4]. I suggest to use HAVE_WIN32 instead (also in this MR).

There's another unrelated problem with MessageModificator and ms-win, but that will be in another MR ;).

Cheers, Nicolas.

[1] https://stackoverflow.com/questions/62962839/stdaligned-alloc-missing-from-visual-studio-2019

[2] !!! https://visualstudio.microsoft.com/vs/pricing-details/ !!!

[3] https://stackoverflow.com/questions/32133203/what-can-i-use-instead-of-stdaligned-alloc-in-ms-visual-studio-2013

[4] https://cmake.org/cmake/help/latest/variable/WIN32.html

Edited by Nicolas Marsic

Merge request reports