File indexing completed on 2024-11-15 09:02:30
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP
0009 #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP
0010
0011 #include <boost/align/detail/is_alignment.hpp>
0012 #include <boost/align/align.hpp>
0013 #include <boost/align/alignment_of.hpp>
0014 #include <boost/assert.hpp>
0015 #include <new>
0016
0017 namespace boost {
0018 namespace alignment {
0019
0020 inline void*
0021 aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
0022 {
0023 BOOST_ASSERT(detail::is_alignment(alignment));
0024 enum {
0025 N = alignment_of<void*>::value
0026 };
0027 if (alignment < N) {
0028 alignment = N;
0029 }
0030 std::size_t n = size + alignment - N;
0031 void* p = ::operator new(sizeof(void*) + n, std::nothrow);
0032 if (p) {
0033 void* r = static_cast<char*>(p) + sizeof(void*);
0034 (void)boost::alignment::align(alignment, size, r, n);
0035 *(static_cast<void**>(r) - 1) = p;
0036 p = r;
0037 }
0038 return p;
0039 }
0040
0041 inline void
0042 aligned_free(void* ptr) BOOST_NOEXCEPT
0043 {
0044 if (ptr) {
0045 ::operator delete(*(static_cast<void**>(ptr) - 1));
0046 }
0047 }
0048
0049 }
0050 }
0051
0052 #endif