File indexing completed on 2026-05-03 08:13:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
0010 #define _LIBCPP___CXX03___MEMORY_RESOURCE_UNSYNCHRONIZED_POOL_RESOURCE_H
0011
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__memory_resource/memory_resource.h>
0014 #include <__cxx03/__memory_resource/pool_options.h>
0015 #include <__cxx03/cstddef>
0016 #include <__cxx03/cstdint>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 #if _LIBCPP_STD_VER >= 17
0023
0024 _LIBCPP_BEGIN_NAMESPACE_STD
0025
0026 namespace pmr {
0027
0028
0029
0030 class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI unsynchronized_pool_resource : public memory_resource {
0031 class __fixed_pool;
0032
0033 class __adhoc_pool {
0034 struct __chunk_footer;
0035 __chunk_footer* __first_;
0036
0037 public:
0038 _LIBCPP_HIDE_FROM_ABI explicit __adhoc_pool() : __first_(nullptr) {}
0039
0040 void __release_ptr(memory_resource* __upstream);
0041 void* __do_allocate(memory_resource* __upstream, size_t __bytes, size_t __align);
0042 void __do_deallocate(memory_resource* __upstream, void* __p, size_t __bytes, size_t __align);
0043 };
0044
0045 static const size_t __min_blocks_per_chunk = 16;
0046 static const size_t __min_bytes_per_chunk = 1024;
0047 static const size_t __max_blocks_per_chunk = (size_t(1) << 20);
0048 static const size_t __max_bytes_per_chunk = (size_t(1) << 30);
0049
0050 static const int __log2_smallest_block_size = 3;
0051 static const size_t __smallest_block_size = 8;
0052 static const size_t __default_largest_block_size = (size_t(1) << 20);
0053 static const size_t __max_largest_block_size = (size_t(1) << 30);
0054
0055 size_t __pool_block_size(int __i) const;
0056 int __log2_pool_block_size(int __i) const;
0057 int __pool_index(size_t __bytes, size_t __align) const;
0058
0059 public:
0060 unsynchronized_pool_resource(const pool_options& __opts, memory_resource* __upstream);
0061
0062 _LIBCPP_HIDE_FROM_ABI unsynchronized_pool_resource()
0063 : unsynchronized_pool_resource(pool_options(), get_default_resource()) {}
0064
0065 _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(memory_resource* __upstream)
0066 : unsynchronized_pool_resource(pool_options(), __upstream) {}
0067
0068 _LIBCPP_HIDE_FROM_ABI explicit unsynchronized_pool_resource(const pool_options& __opts)
0069 : unsynchronized_pool_resource(__opts, get_default_resource()) {}
0070
0071 unsynchronized_pool_resource(const unsynchronized_pool_resource&) = delete;
0072
0073 _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~unsynchronized_pool_resource() override { release(); }
0074
0075 unsynchronized_pool_resource& operator=(const unsynchronized_pool_resource&) = delete;
0076
0077 void release();
0078
0079 _LIBCPP_HIDE_FROM_ABI memory_resource* upstream_resource() const { return __res_; }
0080
0081 [[__gnu__::__pure__]] pool_options options() const;
0082
0083 protected:
0084 void* do_allocate(size_t __bytes, size_t __align) override;
0085
0086 void do_deallocate(void* __p, size_t __bytes, size_t __align) override;
0087
0088 _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool do_is_equal(const memory_resource& __other) const _NOEXCEPT override {
0089 return &__other == this;
0090 }
0091
0092 private:
0093 memory_resource* __res_;
0094 __adhoc_pool __adhoc_pool_;
0095 __fixed_pool* __fixed_pools_;
0096 int __num_fixed_pools_;
0097 uint32_t __options_max_blocks_per_chunk_;
0098 };
0099
0100 }
0101
0102 _LIBCPP_END_NAMESPACE_STD
0103
0104 #endif
0105
0106 #endif