2 // impl/handler_alloc_hook.ipp
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_IMPL_HANDLER_ALLOC_HOOK_IPP
12 #define BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
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/call_stack.hpp>
20 #include <boost/asio/handler_alloc_hook.hpp>
22 #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
23 # if defined(BOOST_ASIO_HAS_IOCP)
24 # include <boost/asio/detail/win_iocp_thread_info.hpp>
25 # else // defined(BOOST_ASIO_HAS_IOCP)
26 # include <boost/asio/detail/task_io_service_thread_info.hpp>
27 # endif // defined(BOOST_ASIO_HAS_IOCP)
28 #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
30 #include <boost/asio/detail/push_options.hpp>
35 #if defined(BOOST_ASIO_HAS_IOCP)
36 namespace detail { class win_iocp_io_service; }
37 #endif // defined(BOOST_ASIO_HAS_IOCP)
39 void* asio_handler_allocate(std::size_t size, ...)
41 #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
42 # if defined(BOOST_ASIO_HAS_IOCP)
43 typedef detail::win_iocp_io_service io_service_impl;
44 typedef detail::win_iocp_thread_info thread_info;
45 # else // defined(BOOST_ASIO_HAS_IOCP)
46 typedef detail::task_io_service io_service_impl;
47 typedef detail::task_io_service_thread_info thread_info;
48 # endif // defined(BOOST_ASIO_HAS_IOCP)
49 typedef detail::call_stack<io_service_impl, thread_info> call_stack;
50 return thread_info::allocate(call_stack::top(), size);
51 #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
52 return ::operator new(size);
53 #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
56 void asio_handler_deallocate(void* pointer, std::size_t size, ...)
58 #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
59 # if defined(BOOST_ASIO_HAS_IOCP)
60 typedef detail::win_iocp_io_service io_service_impl;
61 typedef detail::win_iocp_thread_info thread_info;
62 # else // defined(BOOST_ASIO_HAS_IOCP)
63 typedef detail::task_io_service io_service_impl;
64 typedef detail::task_io_service_thread_info thread_info;
65 # endif // defined(BOOST_ASIO_HAS_IOCP)
66 typedef detail::call_stack<io_service_impl, thread_info> call_stack;
67 thread_info::deallocate(call_stack::top(), pointer, size);
68 #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
70 ::operator delete(pointer);
71 #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
77 #include <boost/asio/detail/pop_options.hpp>
79 #endif // BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP