issue#11: cds: changed __CDS_ guard prefix to CDSLIB_ for all .h files
[libcds.git] / cds / os / libc / alloc_aligned.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_OS_LIBC_ALLOC_ALIGNED_H
4 #define CDSLIB_OS_LIBC_ALLOC_ALIGNED_H
5
6 #include <stdlib.h>
7
8 //@cond none
9 namespace cds { namespace OS {
10     CDS_CXX11_INLINE_NAMESPACE namespace libc {
11         /// Allocates memory on a specified alignment boundary
12         static inline void * aligned_malloc(
13             size_t nSize,       ///< Size of the requested memory allocation
14             size_t nAlignment   ///< The alignment value, which must be an integer power of 2
15             )
16         {
17             return ::memalign( nAlignment, nSize );
18         }
19
20         /// Frees a block of memory that was allocated with aligned_malloc.
21         static inline void aligned_free(
22             void * pBlock   ///< A pointer to the memory block that was returned to the aligned_malloc function
23             )
24         {
25             ::free( pBlock );
26         }
27     }   // namespace libc
28
29 #ifndef CDS_CXX11_INLINE_NAMESPACE_SUPPORT
30     using libc::aligned_malloc;
31     using libc::aligned_free;
32 #endif
33
34 }} // namespace cds::OS
35 //@endcond
36
37 #endif // #ifndef CDSLIB_OS_LIBC_ALLOC_ALIGNED_H
38