Chris@16: // Chris@16: // handler_alloc_hook.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_HANDLER_ALLOC_HOOK_HPP Chris@16: #define BOOST_ASIO_HANDLER_ALLOC_HOOK_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: Chris@16: /// Default allocation function for handlers. Chris@16: /** Chris@16: * Asynchronous operations may need to allocate temporary objects. Since Chris@16: * asynchronous operations have a handler function object, these temporary Chris@16: * objects can be said to be associated with the handler. Chris@16: * Chris@16: * Implement asio_handler_allocate and asio_handler_deallocate for your own Chris@16: * handlers to provide custom allocation for these temporary objects. Chris@16: * Chris@16: * The default implementation of these allocation hooks uses ::operator Chris@16: * new and ::operator delete. Chris@16: * Chris@16: * @note All temporary objects associated with a handler will be deallocated Chris@16: * before the upcall to the handler is performed. This allows the same memory to Chris@16: * be reused for a subsequent asynchronous operation initiated by the handler. Chris@16: * Chris@16: * @par Example Chris@16: * @code Chris@16: * class my_handler; Chris@16: * Chris@16: * void* asio_handler_allocate(std::size_t size, my_handler* context) Chris@16: * { Chris@16: * return ::operator new(size); Chris@16: * } Chris@16: * Chris@16: * void asio_handler_deallocate(void* pointer, std::size_t size, Chris@16: * my_handler* context) Chris@16: * { Chris@16: * ::operator delete(pointer); Chris@16: * } Chris@16: * @endcode Chris@16: */ Chris@16: BOOST_ASIO_DECL void* asio_handler_allocate( Chris@16: std::size_t size, ...); Chris@16: Chris@16: /// Default deallocation function for handlers. Chris@16: /** Chris@16: * Implement asio_handler_allocate and asio_handler_deallocate for your own Chris@16: * handlers to provide custom allocation for the associated temporary objects. Chris@16: * Chris@16: * The default implementation of these allocation hooks uses ::operator Chris@16: * new and ::operator delete. Chris@16: * Chris@16: * @sa asio_handler_allocate. Chris@16: */ Chris@16: BOOST_ASIO_DECL void asio_handler_deallocate( Chris@16: void* pointer, std::size_t size, ...); Chris@16: Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // BOOST_ASIO_HANDLER_ALLOC_HOOK_HPP