From 8a1de2655ce9790d5f0360e2baefb0f5c0fe2944 Mon Sep 17 00:00:00 2001 From: Joost VandeVondele Date: Sat, 9 May 2020 19:45:07 +0200 Subject: [PATCH] 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. --- src/misc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } -- 2.39.2