1//
2// impl/handler_alloc_hook.ipp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
5// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6//
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)
9//
10
11#ifndef BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
12#define BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19#include <boost/asio/detail/thread_context.hpp>
20#include <boost/asio/detail/thread_info_base.hpp>
21#include <boost/asio/handler_alloc_hook.hpp>
22
23#include <boost/asio/detail/push_options.hpp>
24
25namespace boost {
26namespace asio {
27
28void* asio_handler_allocate(std::size_t size, ...)
29{
30#if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
31  return detail::thread_info_base::allocate(
32      detail::thread_context::thread_call_stack::top(), size);
33#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
34  return ::operator new(size);
35#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
36}
37
38void asio_handler_deallocate(void* pointer, std::size_t size, ...)
39{
40#if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
41  detail::thread_info_base::deallocate(
42      detail::thread_context::thread_call_stack::top(), pointer, size);
43#else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
44  (void)size;
45  ::operator delete(pointer);
46#endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
47}
48
49} // namespace asio
50} // namespace boost
51
52#include <boost/asio/detail/pop_options.hpp>
53
54#endif // BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
55