posix_memalign() will be doc’d for 6.2.0…
Although there’s more doc work to be done,
here’s what we’ve got so far:
posix_memalign() Allocate aligned memory
int posix_memalign( void ** memptr,
size_t size );
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 value of alignment must be a multiple of size(void*).
-1 An error occurred (errno is set).
EINVAL The value of alignment isn’t a multiple of size( void *).
ENOMEM There’s insufficient memory available with the requested alignment.
Cancellation point No
Interrupt handler No
Signal handler Yes
errno, free(), malloc()
Igor Kovalenko <Igor.Kovalenko@motorola.com> wrote:
There is (undocumented) posix_memalign() which does just that. It is
from one of draft POSIX specs. Grep headers >
The malloc() currently aligns on 4, but that will be changed to 8 (i’ve
heard). As a general rule, malloc() in all OSes aligns to what compiler
thinks is size of the largest primitive datatype.
Andray Kaganovsky wrote:
is there library routine that would allow me to allocate buffer of
‘size’ bytes aligned at ‘alignment’ boundary (for example,
512 bytes buffer aligned at 4 byte boundary) ? Both’size’
and ‘alignment’ are powers of 2.
If I want to align pointer upward to ‘alignment’ boundary (where
‘alignment’ is power of 2), is this the reliable way to do it:
((void *) ((char *)p + ((int)p % alignment)))
Thanks in advance,