1// 2// impl/handler_alloc_hook.ipp 3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4// 5// Copyright (c) 2003-2015 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 ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP 12#define ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP 13 14 15#include "asio/detail/config.hpp" 16#include "asio/detail/call_stack.hpp" 17#include "asio/handler_alloc_hook.hpp" 18 19#if !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 20# include "asio/detail/task_io_service_thread_info.hpp" 21#endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 22 23#include "asio/detail/push_options.hpp" 24 25namespace asio { 26 27 28void* asio_handler_allocate(std::size_t size, ...) 29{ 30#if !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 31 typedef detail::task_io_service io_service_impl; 32 typedef detail::task_io_service_thread_info thread_info; 33 typedef detail::call_stack<io_service_impl, thread_info> call_stack; 34 return thread_info::allocate(call_stack::top(), size); 35#else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 36 return ::operator new(size); 37#endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 38} 39 40void asio_handler_deallocate(void* pointer, std::size_t size, ...) 41{ 42#if !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 43 typedef detail::task_io_service io_service_impl; 44 typedef detail::task_io_service_thread_info thread_info; 45 typedef detail::call_stack<io_service_impl, thread_info> call_stack; 46 thread_info::deallocate(call_stack::top(), pointer, size); 47#else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 48 (void)size; 49 ::operator delete(pointer); 50#endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING) 51} 52 53} // namespace asio 54 55#include "asio/detail/pop_options.hpp" 56 57#endif // ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP 58