29#ifndef _MALLOC_ALLOCATOR_H
30#define _MALLOC_ALLOCATOR_H 1
37#if __cplusplus >= 201103L
41namespace __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 (__builtin_expect(__n > this->_M_max_size(),
false))
115 if (__n > (std::size_t(-1) /
sizeof(_Tp)))
116 std::__throw_bad_array_new_length();
117 std::__throw_bad_alloc();
122#if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC
123 if (
alignof(_Tp) >
alignof(std::max_align_t))
125 __ret =
static_cast<_Tp*
>(::aligned_alloc(
alignof(_Tp),
129# define _GLIBCXX_CHECK_MALLOC_RESULT
133 __ret =
static_cast<_Tp*
>(std::malloc(__n *
sizeof(_Tp)));
135 std::__throw_bad_alloc();
136#ifdef _GLIBCXX_CHECK_MALLOC_RESULT
137#undef _GLIBCXX_CHECK_MALLOC_RESULT
138 if (
reinterpret_cast<std::size_t
>(__ret) %
alignof(_Tp))
141 deallocate(__ret, __n);
142 std::__throw_bad_alloc();
150 deallocate(_Tp* __p, size_type)
151 { std::free(
static_cast<void*
>(__p)); }
153#if __cplusplus <= 201703L
155 max_size()
const _GLIBCXX_USE_NOEXCEPT
156 {
return _M_max_size(); }
158#if __cplusplus >= 201103L
159 template<
typename _Up,
typename... _Args>
161 construct(_Up* __p, _Args&&... __args)
163 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
165 template<
typename _Up>
174 construct(pointer __p,
const _Tp& __val)
175 { ::new((
void *)__p) value_type(__val); }
178 destroy(pointer __p) { __p->~_Tp(); }
182 template<
typename _Up>
183 friend _GLIBCXX20_CONSTEXPR
bool
188#if __cpp_impl_three_way_comparison < 201907L
189 template<
typename _Up>
190 friend _GLIBCXX20_CONSTEXPR
bool
197 _GLIBCXX_CONSTEXPR size_type
198 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
200#if __PTRDIFF_MAX__ < __SIZE_MAX__
201 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
203 return std::size_t(-1) /
sizeof(_Tp);
208_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.