handler_alloc_hook.ipp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // impl/handler_alloc_hook.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_IMPL_HANDLER_ALLOC_HOOK_IPP
  11. #define BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
  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 <boost/asio/detail/thread_context.hpp>
  17. #include <boost/asio/detail/thread_info_base.hpp>
  18. #include <boost/asio/handler_alloc_hook.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. void* asio_handler_allocate(std::size_t size, ...)
  23. {
  24. #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  25. return detail::thread_info_base::allocate(
  26. detail::thread_context::thread_call_stack::top(), size);
  27. #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  28. return ::operator new(size);
  29. #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  30. }
  31. void asio_handler_deallocate(void* pointer, std::size_t size, ...)
  32. {
  33. #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  34. detail::thread_info_base::deallocate(
  35. detail::thread_context::thread_call_stack::top(), pointer, size);
  36. #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  37. (void)size;
  38. ::operator delete(pointer);
  39. #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  40. }
  41. } // namespace asio
  42. } // namespace boost
  43. #include <boost/asio/detail/pop_options.hpp>
  44. #endif // BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP