File indexing completed on 2026-05-03 08:13:57
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___MEMORY_RESOURCE_MEMORY_RESOURCE_H
0010 #define _LIBCPP___MEMORY_RESOURCE_MEMORY_RESOURCE_H
0011
0012 #include <__config>
0013 #include <__cstddef/max_align_t.h>
0014 #include <__cstddef/size_t.h>
0015 #include <__fwd/memory_resource.h>
0016
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 # pragma GCC system_header
0019 #endif
0020
0021 #if _LIBCPP_STD_VER >= 17
0022
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024
0025 namespace pmr {
0026
0027
0028
0029 class _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource {
0030 static const size_t __max_align = alignof(max_align_t);
0031
0032 public:
0033 virtual ~memory_resource();
0034
0035 [[nodiscard]] [[using __gnu__: __returns_nonnull__, __alloc_size__(2), __alloc_align__(3)]]
0036 _LIBCPP_HIDE_FROM_ABI void* allocate(size_t __bytes, size_t __align = __max_align) {
0037 return do_allocate(__bytes, __align);
0038 }
0039
0040 [[__gnu__::__nonnull__]] _LIBCPP_HIDE_FROM_ABI void
0041 deallocate(void* __p, size_t __bytes, size_t __align = __max_align) {
0042 do_deallocate(__p, __bytes, __align);
0043 }
0044
0045 _LIBCPP_HIDE_FROM_ABI bool is_equal(const memory_resource& __other) const noexcept { return do_is_equal(__other); }
0046
0047 private:
0048 virtual void* do_allocate(size_t, size_t) = 0;
0049 virtual void do_deallocate(void*, size_t, size_t) = 0;
0050 virtual bool do_is_equal(memory_resource const&) const noexcept = 0;
0051 };
0052
0053
0054
0055 inline _LIBCPP_AVAILABILITY_PMR _LIBCPP_HIDE_FROM_ABI bool
0056 operator==(const memory_resource& __lhs, const memory_resource& __rhs) noexcept {
0057 return &__lhs == &__rhs || __lhs.is_equal(__rhs);
0058 }
0059
0060 # if _LIBCPP_STD_VER <= 17
0061
0062 inline _LIBCPP_AVAILABILITY_PMR _LIBCPP_HIDE_FROM_ABI bool
0063 operator!=(const memory_resource& __lhs, const memory_resource& __rhs) noexcept {
0064 return !(__lhs == __rhs);
0065 }
0066
0067 # endif
0068
0069
0070
0071 [[__gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
0072 get_default_resource() noexcept;
0073
0074 [[__gnu__::__returns_nonnull__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
0075 set_default_resource(memory_resource*) noexcept;
0076
0077 [[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
0078 new_delete_resource() noexcept;
0079
0080 [[using __gnu__: __returns_nonnull__, __const__]] _LIBCPP_AVAILABILITY_PMR _LIBCPP_EXPORTED_FROM_ABI memory_resource*
0081 null_memory_resource() noexcept;
0082
0083 }
0084
0085 _LIBCPP_END_NAMESPACE_STD
0086
0087 #endif
0088
0089 #endif