/* 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