3 #ifndef __CDS_OS_POSIX_ALLOC_ALIGNED_H
4 #define __CDS_OS_POSIX_ALLOC_ALIGNED_H
10 # define _XOPEN_SOURCE 600
16 namespace cds { namespace OS {
18 /// Allocates memory on a specified alignment boundary
19 static inline void * aligned_malloc(
20 size_t nSize, ///< Size of the requested memory allocation
21 size_t nAlignment ///< The alignment value, which must be an integer power of 2
25 return ::posix_memalign( &pMem, nAlignment, nSize ) == 0 ? pMem : NULL;
28 /// Frees a block of memory that was allocated with aligned_malloc.
29 static inline void aligned_free(
30 void * pBlock ///< A pointer to the memory block that was returned to the aligned_malloc function
37 using posix::aligned_malloc;
38 using posix::aligned_free;
40 }} // namespace cds::OS
44 #endif // #ifndef __CDS_OS_POSIX_ALLOC_ALIGNED_H