Use posix_memalign instead of aligned_alloc
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Sat, 9 May 2020 17:45:07 +0000 (19:45 +0200)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Mon, 11 May 2020 18:41:49 +0000 (20:41 +0200)
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

index 4d6483e73d20f78d352429bbc24289a648fc3649..946810088da8a3ee74989215c852029e8879c1cb 100644 (file)
@@ -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;
 }