2 // detail/handler_alloc_helpers.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
12 #define BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/addressof.hpp>
20 #include <boost/asio/detail/noncopyable.hpp>
21 #include <boost/asio/handler_alloc_hook.hpp>
23 #include <boost/asio/detail/push_options.hpp>
25 // Calls to asio_handler_allocate and asio_handler_deallocate must be made from
26 // a namespace that does not contain any overloads of these functions. The
27 // boost_asio_handler_alloc_helpers namespace is defined here for that purpose.
28 namespace boost_asio_handler_alloc_helpers {
30 template <typename Handler>
31 inline void* allocate(std::size_t s, Handler& h)
33 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
34 return ::operator new(s);
36 using boost::asio::asio_handler_allocate;
37 return asio_handler_allocate(s, boost::asio::detail::addressof(h));
41 template <typename Handler>
42 inline void deallocate(void* p, std::size_t s, Handler& h)
44 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
47 using boost::asio::asio_handler_deallocate;
48 asio_handler_deallocate(p, s, boost::asio::detail::addressof(h));
52 } // namespace boost_asio_handler_alloc_helpers
54 #define BOOST_ASIO_DEFINE_HANDLER_PTR(op) \
73 boost_asio_handler_alloc_helpers::deallocate(v, sizeof(op), *h); \
80 #include <boost/asio/detail/pop_options.hpp>
82 #endif // BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP