MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / aligned_new

Function aligned_new

3rd/asio-1.24.0/include/asio/detail/memory.hpp:96–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94#endif // defined(ASIO_HAS_CXX11_ALLOCATORS)
95
96inline void* aligned_new(std::size_t align, std::size_t size)
97{
98#if defined(ASIO_HAS_STD_ALIGNED_ALLOC) && defined(ASIO_HAS_ALIGNOF)
99 align = (align < ASIO_DEFAULT_ALIGN) ? ASIO_DEFAULT_ALIGN : align;
100 size = (size % align == 0) ? size : size + (align - size % align);
101 void* ptr = std::aligned_alloc(align, size);
102 if (!ptr)
103 {
104 std::bad_alloc ex;
105 asio::detail::throw_exception(ex);
106 }
107 return ptr;
108#elif defined(ASIO_HAS_BOOST_ALIGN) && defined(ASIO_HAS_ALIGNOF)
109 align = (align < ASIO_DEFAULT_ALIGN) ? ASIO_DEFAULT_ALIGN : align;
110 size = (size % align == 0) ? size : size + (align - size % align);
111 void* ptr = boost::alignment::aligned_alloc(align, size);
112 if (!ptr)
113 {
114 std::bad_alloc ex;
115 asio::detail::throw_exception(ex);
116 }
117 return ptr;
118#elif defined(ASIO_MSVC) && defined(ASIO_HAS_ALIGNOF)
119 align = (align < ASIO_DEFAULT_ALIGN) ? ASIO_DEFAULT_ALIGN : align;
120 size = (size % align == 0) ? size : size + (align - size % align);
121 void* ptr = _aligned_malloc(size, align);
122 if (!ptr)
123 {
124 std::bad_alloc ex;
125 asio::detail::throw_exception(ex);
126 }
127 return ptr;
128#else // defined(ASIO_MSVC) && defined(ASIO_HAS_ALIGNOF)
129 (void)align;
130 return ::operator new(size);
131#endif // defined(ASIO_MSVC) && defined(ASIO_HAS_ALIGNOF)
132}
133
134inline void aligned_delete(void* ptr)
135{

Callers 2

allocateFunction · 0.85
allocateFunction · 0.85

Calls 4

aligned_allocFunction · 0.85
throw_exceptionFunction · 0.85
_aligned_mallocFunction · 0.85
operator newFunction · 0.85

Tested by

no test coverage detected