From 508a38a7fa572572869e7730f6c50957d59ff38d Mon Sep 17 00:00:00 2001 From: Yaser Afshar Date: Wed, 15 Jul 2020 17:49:49 -0500 Subject: [PATCH] Fix the system-dependent function call to `malloc_usable_size`. Fix the system-dependent function call to get the size of the block of memory allocated from the heap. --- src/memory.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/memory.cpp b/src/memory.cpp index 873bc754c0..6211687a7a 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -22,9 +22,13 @@ #include "tbb/scalable_allocator.h" #else #include +#if defined(__APPLE__) +#include +#else #include #endif #endif +#endif #if defined(LMP_USER_INTEL) && !defined(LAMMPS_MEMALIGN) && !defined(_WIN32) #define LAMMPS_MEMALIGN 64 @@ -84,7 +88,13 @@ void *Memory::srealloc(void *ptr, bigint nbytes, const char *name) if (offset) { void *optr = ptr; ptr = smalloc(nbytes, name); +#if defined(__APPLE__) + memcpy(ptr, optr, MIN(nbytes,malloc_size(optr))); +#elif defined(_WIN32) || defined(__MINGW32__) + memcpy(ptr, optr, MIN(nbytes,_msize(optr))); +#else memcpy(ptr, optr, MIN(nbytes,malloc_usable_size(optr))); +#endif free(optr); } #else