Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.1KB

  1. //
  2. // detail/recycling_allocator.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. #ifndef ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP
  11. #define ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP
  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/detail/push_options.hpp"
  20. namespace asio {
  21. namespace detail {
  22. template <typename T>
  23. class recycling_allocator
  24. {
  25. public:
  26. template <typename U>
  27. struct rebind
  28. {
  29. typedef recycling_allocator<U> other;
  30. };
  31. recycling_allocator()
  32. {
  33. }
  34. template <typename U>
  35. recycling_allocator(const recycling_allocator<U>&)
  36. {
  37. }
  38. T* allocate(std::size_t n)
  39. {
  40. typedef thread_context::thread_call_stack call_stack;
  41. void* p = thread_info_base::allocate(call_stack::top(), sizeof(T) * n);
  42. return static_cast<T*>(p);
  43. }
  44. void deallocate(T* p, std::size_t n)
  45. {
  46. typedef thread_context::thread_call_stack call_stack;
  47. thread_info_base::deallocate(call_stack::top(), p, sizeof(T) * n);
  48. }
  49. };
  50. template <>
  51. class recycling_allocator<void>
  52. {
  53. public:
  54. template <typename U>
  55. struct rebind
  56. {
  57. typedef recycling_allocator<U> other;
  58. };
  59. recycling_allocator()
  60. {
  61. }
  62. template <typename U>
  63. recycling_allocator(const recycling_allocator<U>&)
  64. {
  65. }
  66. };
  67. template <typename Allocator>
  68. struct get_recycling_allocator
  69. {
  70. typedef Allocator type;
  71. static type get(const Allocator& a) { return a; }
  72. };
  73. template <typename T>
  74. struct get_recycling_allocator<std::allocator<T> >
  75. {
  76. typedef recycling_allocator<T> type;
  77. static type get(const std::allocator<T>&) { return type(); }
  78. };
  79. } // namespace detail
  80. } // namespace asio
  81. #include "asio/detail/pop_options.hpp"
  82. #endif // ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP