libstdc++
memory
Go to the documentation of this file.
1 // <memory> -*- C++ -*-
2 
3 // Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
25 /*
26  * Copyright (c) 1997-1999
27  * Silicon Graphics Computer Systems, Inc.
28  *
29  * Permission to use, copy, modify, distribute and sell this software
30  * and its documentation for any purpose is hereby granted without fee,
31  * provided that the above copyright notice appear in all copies and
32  * that both that copyright notice and this permission notice appear
33  * in supporting documentation. Silicon Graphics makes no
34  * representations about the suitability of this software for any
35  * purpose. It is provided "as is" without express or implied warranty.
36  *
37  */
38 
39 /** @file include/memory
40  * This is a Standard C++ Library header.
41  * @ingroup memory
42  */
43 
44 #ifndef _GLIBCXX_MEMORY
45 #define _GLIBCXX_MEMORY 1
46 
47 #pragma GCC system_header
48 
49 /**
50  * @defgroup memory Memory
51  * @ingroup utilities
52  *
53  * Components for memory allocation, deallocation, and management.
54  */
55 
56 /**
57  * @defgroup pointer_abstractions Pointer Abstractions
58  * @ingroup memory
59  *
60  * Smart pointers, etc.
61  */
62 
63 #include <bits/memoryfwd.h>
64 #if _GLIBCXX_HOSTED
65 # include <bits/allocator.h>
66 # include <bits/stl_tempbuf.h>
67 #endif
68 #include <bits/stl_construct.h>
69 #include <bits/stl_uninitialized.h>
70 #include <bits/stl_raw_storage_iter.h>
71 
72 #if __cplusplus >= 201103L
73 # include <type_traits>
74 # include <bits/align.h>
75 # include <bits/uses_allocator.h>
76 # include <bits/alloc_traits.h>
77 # include <debug/debug.h>
78 # include <bits/unique_ptr.h>
79 # if _GLIBCXX_HOSTED
80 # include <bits/shared_ptr.h>
81 # include <bits/shared_ptr_atomic.h>
82 # endif
83 #endif
84 
85 #if __cplusplus < 201103L || _GLIBCXX_USE_DEPRECATED
86 # include <backward/auto_ptr.h>
87 #endif
88 
89 #if __cplusplus > 201703L
90 # include <bits/ranges_uninitialized.h>
91 # include <bits/uses_allocator_args.h>
92 #endif
93 
94 #if __cplusplus > 202002L
95 # include <bits/out_ptr.h>
96 #endif
97 
98 #define __glibcxx_want_addressof_constexpr
99 #define __glibcxx_want_allocator_traits_is_always_equal
100 #define __glibcxx_want_assume_aligned
101 #define __glibcxx_want_atomic_shared_ptr
102 #define __glibcxx_want_atomic_value_initialization
103 #define __glibcxx_want_constexpr_dynamic_alloc
104 #define __glibcxx_want_constexpr_memory
105 #define __glibcxx_want_enable_shared_from_this
106 #define __glibcxx_want_make_unique
107 #define __glibcxx_want_out_ptr
108 #define __glibcxx_want_parallel_algorithm
109 #define __glibcxx_want_ranges
110 #define __glibcxx_want_raw_memory_algorithms
111 #define __glibcxx_want_shared_ptr_arrays
112 #define __glibcxx_want_shared_ptr_weak_type
113 #define __glibcxx_want_smart_ptr_for_overwrite
114 #define __glibcxx_want_to_address
115 #define __glibcxx_want_transparent_operators
116 #include <bits/version.h>
117 
118 #if __cplusplus >= 201103L && __cplusplus <= 202002L && _GLIBCXX_HOSTED
119 namespace std _GLIBCXX_VISIBILITY(default)
120 {
121 _GLIBCXX_BEGIN_NAMESPACE_VERSION
122 
123 /** @defgroup ptr_safety Pointer Safety and Garbage Collection
124  * @ingroup memory
125  *
126  * Utilities to assist with garbage collection in an implementation
127  * that supports <em>strict pointer safety</em>.
128  * This implementation only supports <em>relaxed pointer safety</em>
129  * and so these functions have no effect.
130  *
131  * C++11 20.6.4 [util.dynamic.safety], Pointer safety
132  *
133  * @{
134  */
135 
136 /// Constants representing the different types of pointer safety.
137 enum class pointer_safety { relaxed, preferred, strict };
138 
139 /// Inform a garbage collector that an object is still in use.
140 inline void
141 declare_reachable(void*) { }
142 
143 /// Unregister an object previously registered with declare_reachable.
144 template <typename _Tp>
145  inline _Tp*
146  undeclare_reachable(_Tp* __p) { return __p; }
147 
148 /// Inform a garbage collector that a region of memory need not be traced.
149 inline void
150 declare_no_pointers(char*, size_t) { }
151 
152 /// Unregister a range previously registered with declare_no_pointers.
153 inline void
154 undeclare_no_pointers(char*, size_t) { }
155 
156 /// The type of pointer safety supported by the implementation.
157 inline pointer_safety
158 get_pointer_safety() noexcept { return pointer_safety::relaxed; }
159 /// @}
160 
161 _GLIBCXX_END_NAMESPACE_VERSION
162 } // namespace
163 #endif // C++11 to C++20
164 
165 #ifdef __cpp_lib_parallel_algorithm // C++ >= 17 && HOSTED
166 // Parallel STL algorithms
167 # if _PSTL_EXECUTION_POLICIES_DEFINED
168 // If <execution> has already been included, pull in implementations
169 # include <pstl/glue_memory_impl.h>
170 # else
171 // Otherwise just pull in forward declarations
172 # include <pstl/glue_memory_defs.h>
173 # endif
174 #endif // __cpp_lib_parallel_algorithm
175 
176 #endif /* _GLIBCXX_MEMORY */