handler_alloc_hook.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // handler_alloc_hook.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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. #if defined(BOOST_ASIO_NO_DEPRECATED)
  21. // Places in asio that would have previously called the allocate or deallocate
  22. // hooks to manage memory, now call them only to check whether the result types
  23. // are these types. If the result is not the correct type, it indicates that
  24. // the user code still has the old hooks in place, and if so we want to trigger
  25. // a compile error.
  26. enum asio_handler_allocate_is_no_longer_used {};
  27. enum asio_handler_deallocate_is_no_longer_used {};
  28. typedef asio_handler_allocate_is_no_longer_used
  29. asio_handler_allocate_is_deprecated;
  30. typedef asio_handler_deallocate_is_no_longer_used
  31. asio_handler_deallocate_is_deprecated;
  32. #else // defined(BOOST_ASIO_NO_DEPRECATED)
  33. typedef void* asio_handler_allocate_is_deprecated;
  34. typedef void asio_handler_deallocate_is_deprecated;
  35. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  36. /// (Deprecated: Use the associated_allocator trait.) Default allocation
  37. /// function for handlers.
  38. /**
  39. * Asynchronous operations may need to allocate temporary objects. Since
  40. * asynchronous operations have a handler function object, these temporary
  41. * objects can be said to be associated with the handler.
  42. *
  43. * Implement asio_handler_allocate and asio_handler_deallocate for your own
  44. * handlers to provide custom allocation for these temporary objects.
  45. *
  46. * The default implementation of these allocation hooks uses <tt>::operator
  47. * new</tt> and <tt>::operator delete</tt>.
  48. *
  49. * @note All temporary objects associated with a handler will be deallocated
  50. * before the upcall to the handler is performed. This allows the same memory to
  51. * be reused for a subsequent asynchronous operation initiated by the handler.
  52. *
  53. * @par Example
  54. * @code
  55. * class my_handler;
  56. *
  57. * void* asio_handler_allocate(std::size_t size, my_handler* context)
  58. * {
  59. * return ::operator new(size);
  60. * }
  61. *
  62. * void asio_handler_deallocate(void* pointer, std::size_t size,
  63. * my_handler* context)
  64. * {
  65. * ::operator delete(pointer);
  66. * }
  67. * @endcode
  68. */
  69. BOOST_ASIO_DECL asio_handler_allocate_is_deprecated
  70. asio_handler_allocate(std::size_t size, ...);
  71. /// Default deallocation function for handlers.
  72. /**
  73. * Implement asio_handler_allocate and asio_handler_deallocate for your own
  74. * handlers to provide custom allocation for the associated temporary objects.
  75. *
  76. * The default implementation of these allocation hooks uses <tt>::operator
  77. * new</tt> and <tt>::operator delete</tt>.
  78. *
  79. * @sa asio_handler_allocate.
  80. */
  81. BOOST_ASIO_DECL asio_handler_deallocate_is_deprecated
  82. asio_handler_deallocate(void* pointer, std::size_t size, ...);
  83. } // namespace asio
  84. } // namespace boost
  85. #include <boost/asio/detail/pop_options.hpp>
  86. #if defined(BOOST_ASIO_HEADER_ONLY)
  87. # include <boost/asio/impl/handler_alloc_hook.ipp>
  88. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  89. #endif // BOOST_ASIO_HANDLER_ALLOC_HOOK_HPP