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