Home | History | Annotate | Download | only in asio
      1 //
      2 // handler_alloc_hook.hpp
      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_HANDLER_ALLOC_HOOK_HPP
     12 #define ASIO_HANDLER_ALLOC_HOOK_HPP
     13 
     14 
     15 #include "asio/detail/config.hpp"
     16 #include <cstddef>
     17 
     18 #include "asio/detail/push_options.hpp"
     19 
     20 namespace asio {
     21 
     22 /// Default allocation function for handlers.
     23 /**
     24  * Asynchronous operations may need to allocate temporary objects. Since
     25  * asynchronous operations have a handler function object, these temporary
     26  * objects can be said to be associated with the handler.
     27  *
     28  * Implement asio_handler_allocate and asio_handler_deallocate for your own
     29  * handlers to provide custom allocation for these temporary objects.
     30  *
     31  * The default implementation of these allocation hooks uses <tt>::operator
     32  * new</tt> and <tt>::operator delete</tt>.
     33  *
     34  * @note All temporary objects associated with a handler will be deallocated
     35  * before the upcall to the handler is performed. This allows the same memory to
     36  * be reused for a subsequent asynchronous operation initiated by the handler.
     37  *
     38  * @par Example
     39  * @code
     40  * class my_handler;
     41  *
     42  * void* asio_handler_allocate(std::size_t size, my_handler* context)
     43  * {
     44  *   return ::operator new(size);
     45  * }
     46  *
     47  * void asio_handler_deallocate(void* pointer, std::size_t size,
     48  *     my_handler* context)
     49  * {
     50  *   ::operator delete(pointer);
     51  * }
     52  * @endcode
     53  */
     54 ASIO_DECL void* asio_handler_allocate(
     55     std::size_t size, ...);
     56 
     57 /// Default deallocation function for handlers.
     58 /**
     59  * Implement asio_handler_allocate and asio_handler_deallocate for your own
     60  * handlers to provide custom allocation for the associated temporary objects.
     61  *
     62  * The default implementation of these allocation hooks uses <tt>::operator
     63  * new</tt> and <tt>::operator delete</tt>.
     64  *
     65  * @sa asio_handler_allocate.
     66  */
     67 ASIO_DECL void asio_handler_deallocate(
     68     void* pointer, std::size_t size, ...);
     69 
     70 } // namespace asio
     71 
     72 #include "asio/detail/pop_options.hpp"
     73 
     74 # include "asio/impl/handler_alloc_hook.ipp"
     75 
     76 #endif // ASIO_HANDLER_ALLOC_HOOK_HPP
     77