29 #ifndef _MALLOC_ALLOCATOR_H
30 #define _MALLOC_ALLOCATOR_H 1
37 #if __cplusplus >= 201103L
41 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
53 template<
typename _Tp>
57 typedef _Tp value_type;
58 typedef std::size_t size_type;
59 typedef std::ptrdiff_t difference_type;
60 #if __cplusplus <= 201703L
62 typedef const _Tp* const_pointer;
63 typedef _Tp& reference;
64 typedef const _Tp& const_reference;
66 template<
typename _Tp1>
71 #if __cplusplus >= 201103L
83 template<
typename _Tp1>
86 _GLIBCXX_USE_NOEXCEPT { }
88 #if __cplusplus <= 201703L
92 address(reference __x)
const _GLIBCXX_NOEXCEPT
96 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
102 _GLIBCXX_NODISCARD _Tp*
103 allocate(size_type __n,
const void* = 0)
105 #if __cplusplus >= 201103L
108 static_assert(
sizeof(_Tp) != 0,
"cannot allocate incomplete types");
111 if (__n > this->_M_max_size())
112 std::__throw_bad_alloc();
115 #if __cpp_aligned_new
116 #if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC
117 if (
alignof(_Tp) >
alignof(std::max_align_t))
119 __ret =
static_cast<_Tp*
>(::aligned_alloc(
alignof(_Tp),
123 # define _GLIBCXX_CHECK_MALLOC_RESULT
127 __ret =
static_cast<_Tp*
>(std::malloc(__n *
sizeof(_Tp)));
129 std::__throw_bad_alloc();
130 #ifdef _GLIBCXX_CHECK_MALLOC_RESULT
131 #undef _GLIBCXX_CHECK_MALLOC_RESULT
132 if (
reinterpret_cast<std::size_t
>(__ret) %
alignof(_Tp))
135 deallocate(__ret, __n);
136 std::__throw_bad_alloc();
144 deallocate(_Tp* __p, size_type)
145 { std::free(
static_cast<void*
>(__p)); }
147 #if __cplusplus <= 201703L
149 max_size()
const _GLIBCXX_USE_NOEXCEPT
150 {
return _M_max_size(); }
152 #if __cplusplus >= 201103L
153 template<
typename _Up,
typename... _Args>
155 construct(_Up* __p, _Args&&... __args)
157 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
159 template<
typename _Up>
168 construct(pointer __p,
const _Tp& __val)
169 { ::new((
void *)__p) value_type(__val); }
172 destroy(pointer __p) { __p->~_Tp(); }
176 template<
typename _Up>
177 friend _GLIBCXX20_CONSTEXPR
bool
182 #if __cpp_impl_three_way_comparison < 201907L
183 template<
typename _Up>
184 friend _GLIBCXX20_CONSTEXPR
bool
191 _GLIBCXX_CONSTEXPR size_type
192 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
194 #if __PTRDIFF_MAX__ < __SIZE_MAX__
195 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
197 return std::size_t(-1) /
sizeof(_Tp);
202 _GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
GNU extensions for public use.
An allocator that uses malloc.