handler_alloc_hook.hpp 2.5 KB

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