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
Synopsis:
#include <stdlib.h>
int posix_memalign( void ** memptr,
size_t alignment,
size_t size );
Library:
libc
Description:
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*).
Returns:
0 Success.
-1 An error occurred (errno is set).
Errors:
EINVAL The value of alignment isn’t a multiple of size( void *).
ENOMEM There’s insufficient memory available with the requested alignment.
Classification:
POSIX
Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes
See also:
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:
Greetings,
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:
#define ALIGN_PTR_UPWARD(p,alignment)
((void *) ((char *)p + ((int)p % alignment)))
Thanks in advance,
Andray