2 // detail/handler_alloc_helpers.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2011 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 ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
12 #define ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include "asio/detail/config.hpp"
19 #include <boost/detail/workaround.hpp>
20 #include <boost/utility/addressof.hpp>
21 #include "asio/detail/noncopyable.hpp"
22 #include "asio/handler_alloc_hook.hpp"
24 #include "asio/detail/push_options.hpp"
26 // Calls to asio_handler_allocate and asio_handler_deallocate must be made from
27 // a namespace that does not contain any overloads of these functions. The
28 // asio_handler_alloc_helpers namespace is defined here for that purpose.
29 namespace asio_handler_alloc_helpers {
31 template <typename Handler>
32 inline void* allocate(std::size_t s, Handler& h)
34 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) \
35 || BOOST_WORKAROUND(__GNUC__, < 3)
36 return ::operator new(s);
39 return asio_handler_allocate(s, boost::addressof(h));
43 template <typename Handler>
44 inline void deallocate(void* p, std::size_t s, Handler& h)
46 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) \
47 || BOOST_WORKAROUND(__GNUC__, < 3)
51 asio_handler_deallocate(p, s, boost::addressof(h));
55 } // namespace asio_handler_alloc_helpers
57 #define ASIO_DEFINE_HANDLER_PTR(op) \
76 asio_handler_alloc_helpers::deallocate(v, sizeof(op), *h); \
83 #include "asio/detail/pop_options.hpp"
85 #endif // ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP