23 #include "precompiled.h"
31 #define HAVE_POSIX_MEMALIGN (OS_LINUX && !OS_ANDROID)
32 #define HAVE_MEMALIGN OS_LINUX
34 #if HAVE_POSIX_MEMALIGN
39 int ret = posix_memalign(&ptr, alignment, size);
56 return memalign(alignment, size);
64 #else // Fallback aligned allocation using malloc
71 if (align < 2*
sizeof(
void*))
72 align = 2*
sizeof(
void*);
74 void*
const malloc_ptr = malloc(size + align);
81 void*
const aligned_ptr =
82 (
void *)(
round_down(uintptr_t(malloc_ptr), uintptr_t(align)) + align);
85 ENSURE(((
void**)aligned_ptr) - 1 >= malloc_ptr);
88 ((
void **)aligned_ptr)[-1] = malloc_ptr;
96 free(((
void**)alignedPointer)[-1]);
void * rtl_AllocateAligned(size_t size, size_t align)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
T round_down(T n, T multiple)
void rtl_FreeAligned(void *alignedPointer)