|This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.|
Allocate aligned memory
#include <stdlib.h> int posix_memalign( void ** memptr, size_t alignment, size_t size );
- A pointer to a location where posix_memalign() can store a pointer the memory.
- The alignment to use for the memory. This must be a multiple of size( void * ).
- The size, in bytes, of the block to allocate.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The posix_memalign() function allocates size bytes aligned on a boundary specified by alignment. It returns a pointer to the allocated memory in memptr.
The buffer allocated by posix_memalign() is contiguous in virtual address space, but not physical memory. Since some platforms don't allocate memory in 4K page sizes, you shouldn't assume that the memory allocated will be physically contiguous if you specify a size of 4K or less.
You can obtain the physical address of the start of the buffer using mem_offset() with fd=NOFD.
- An error occurred (errno is set).
- The value of alignment isn't a multiple of size( void * ).
- There's insufficient memory available with the requested alignment.