Hi.
Is there any standardized function in GCC or glibc to allocate memory block at aligned pointer? Like _align_malloc() in MSVC?
Hi.
Is there any standardized function in GCC or glibc to allocate memory block at aligned pointer? Like _align_malloc() in MSVC?
It depends on what kind of alignment you expect. Do you want a stricter alignment, or a more relaxed alignment?
malloc
by definition is guaranteed to return a pointer that is properly aligned for storing any standard type in C program (and, therefore, any type built from standard types). Is it what your are looking for? Or do you need something different?
The posix_memalign()
function provides aligned memory allocation and has been available since glibc 2.1.91.
From the posix_memalign()
function documentation in IEEE Std 1003.1-2004:
The posix_memalign() function shall allocate size bytes aligned on a boundary specified by alignment, and shall return a pointer to the allocated memory in memptr. The value of alignment shall be a multiple of sizeof( void *), that is also a power of two. Upon successful completion, the value pointed to by memptr shall be a multiple of alignment.