From: Joost VandeVondele Date: Sat, 9 May 2020 17:45:07 +0000 (+0200) Subject: Use posix_memalign instead of aligned_alloc X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=8a1de2655ce9790d5f0360e2baefb0f5c0fe2944;hp=fcaf0736feb17f1eb639a7ae071acc920b308f74 Use posix_memalign instead of aligned_alloc should be a little more portable to older linux systems (before glibc-2.16). fixes https://github.com/official-stockfish/Stockfish/issues/2665 closes https://github.com/official-stockfish/Stockfish/pull/2668 No functional change. --- diff --git a/src/misc.cpp b/src/misc.cpp index 4d6483e7..94681008 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -303,7 +303,8 @@ void* aligned_ttmem_alloc(size_t allocSize, void*& mem) { constexpr size_t alignment = 2 * 1024 * 1024; // assumed 2MB page sizes size_t size = ((allocSize + alignment - 1) / alignment) * alignment; // multiple of alignment - mem = aligned_alloc(alignment, size); + if (posix_memalign(&mem, alignment, size)) + mem = nullptr; madvise(mem, allocSize, MADV_HUGEPAGE); return mem; }