handler_alloc_hook.ipp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // impl/handler_alloc_hook.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 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 ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include "asio/detail/memory.hpp"
  17. #include "asio/detail/thread_context.hpp"
  18. #include "asio/detail/thread_info_base.hpp"
  19. #include "asio/handler_alloc_hook.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. asio_handler_allocate_is_deprecated
  23. asio_handler_allocate(std::size_t size, ...)
  24. {
  25. #if defined(ASIO_NO_DEPRECATED)
  26. (void)size;
  27. return asio_handler_allocate_is_no_longer_used();
  28. #elif !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  29. return detail::thread_info_base::allocate(
  30. detail::thread_context::top_of_thread_call_stack(), size);
  31. #else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  32. return aligned_new(ASIO_DEFAULT_ALIGN, size);
  33. #endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  34. }
  35. asio_handler_deallocate_is_deprecated
  36. asio_handler_deallocate(void* pointer, std::size_t size, ...)
  37. {
  38. #if defined(ASIO_NO_DEPRECATED)
  39. (void)pointer;
  40. (void)size;
  41. return asio_handler_deallocate_is_no_longer_used();
  42. #elif !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  43. detail::thread_info_base::deallocate(
  44. detail::thread_context::top_of_thread_call_stack(), pointer, size);
  45. #else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  46. (void)size;
  47. aligned_delete(pointer)
  48. #endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  49. }
  50. } // namespace asio
  51. #include "asio/detail/pop_options.hpp"
  52. #endif // ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP