// detail/handler_alloc_helpers.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#endif // defined(BOOST_ASIO_NO_DEPRECATED)
template <typename Handler>
-inline void* allocate(std::size_t s, Handler& h)
+inline void* allocate(std::size_t s, Handler& h,
+ std::size_t align = BOOST_ASIO_DEFAULT_ALIGN)
{
#if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
- return ::operator new(s);
+ return aligned_new(align, s);
#elif defined(BOOST_ASIO_NO_DEPRECATED)
// The asio_handler_allocate hook is no longer used to obtain memory.
(void)&error_if_hooks_are_defined<Handler>;
(void)h;
-#if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
+# if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
return boost::asio::detail::thread_info_base::allocate(
- boost::asio::detail::thread_context::thread_call_stack::top(), s);
-#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
- return ::operator new(size);
-#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
+ boost::asio::detail::thread_context::top_of_thread_call_stack(),
+ s, align);
+# else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
+ return aligned_new(align, s);
+# endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
#else
+ (void)align;
using boost::asio::asio_handler_allocate;
return asio_handler_allocate(s, boost::asio::detail::addressof(h));
#endif
inline void deallocate(void* p, std::size_t s, Handler& h)
{
#if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
- ::operator delete(p);
+ aligned_delete(p);
#elif defined(BOOST_ASIO_NO_DEPRECATED)
// The asio_handler_allocate hook is no longer used to obtain memory.
(void)&error_if_hooks_are_defined<Handler>;
(void)h;
#if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
boost::asio::detail::thread_info_base::deallocate(
- boost::asio::detail::thread_context::thread_call_stack::top(), p, s);
+ boost::asio::detail::thread_context::top_of_thread_call_stack(), p, s);
#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
(void)s;
- ::operator delete(p);
+ aligned_delete(p);
#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
#else
using boost::asio::asio_handler_deallocate;
T* allocate(std::size_t n)
{
return static_cast<T*>(
- boost_asio_handler_alloc_helpers::allocate(sizeof(T) * n, handler_));
+ boost_asio_handler_alloc_helpers::allocate(
+ sizeof(T) * n, handler_, BOOST_ASIO_ALIGNOF(T)));
}
void deallocate(T* p, std::size_t n)