From: Nathan Moinvaziri Date: Thu, 4 Jan 2024 22:32:06 +0000 (-0800) Subject: Prefer HAVE_ALIGNED_ALLOC when available in zng_alloc X-Git-Tag: 2.2.0~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42db8b86a842e92e2dd9695860b03bcbdf3fe1c0;p=thirdparty%2Fzlib-ng.git Prefer HAVE_ALIGNED_ALLOC when available in zng_alloc Added some more helpful comments for people who come across this code. --- diff --git a/zutil_p.h b/zutil_p.h index caec91d5..bc6f9698 100644 --- a/zutil_p.h +++ b/zutil_p.h @@ -16,15 +16,17 @@ /* Function to allocate 16 or 64-byte aligned memory */ static inline void *zng_alloc(size_t size) { -#ifdef HAVE_POSIX_MEMALIGN +#ifdef HAVE_ALIGNED_ALLOC + return (void *)aligned_alloc(64, size); /* Defined in C11 */ +#elif defined(HAVE_POSIX_MEMALIGN) void *ptr; return posix_memalign(&ptr, 64, size) ? NULL : ptr; #elif defined(_WIN32) return (void *)_aligned_malloc(size, 64); #elif defined(__APPLE__) - return (void *)malloc(size); /* MacOS always aligns to 16 bytes */ -#elif defined(HAVE_ALIGNED_ALLOC) - return (void *)aligned_alloc(64, size); + /* Fallback for when posix_memalign and aligned_alloc are not available. + * On macOS, it always aligns to 16 bytes. */ + return (void *)malloc(size); #else return (void *)memalign(64, size); #endif