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
103 allocate(size_type __n,
const void* = 0)
105 if (__n > this->_M_max_size())
106 std::__throw_bad_alloc();
109 #if __cpp_aligned_new
110 #if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC
111 if (
alignof(_Tp) >
alignof(std::max_align_t))
113 __ret =
static_cast<_Tp*
>(::aligned_alloc(
alignof(_Tp),
117 # define _GLIBCXX_CHECK_MALLOC_RESULT
121 __ret =
static_cast<_Tp*
>(std::malloc(__n *
sizeof(_Tp)));
123 std::__throw_bad_alloc();
124 #ifdef _GLIBCXX_CHECK_MALLOC_RESULT
125 #undef _GLIBCXX_CHECK_MALLOC_RESULT
126 if (
reinterpret_cast<std::size_t
>(__ret) %
alignof(_Tp))
129 deallocate(__ret, __n);
130 std::__throw_bad_alloc();
138 deallocate(_Tp* __p, size_type)
139 { std::free(
static_cast<void*
>(__p)); }
141 #if __cplusplus <= 201703L
143 max_size()
const _GLIBCXX_USE_NOEXCEPT
144 {
return _M_max_size(); }
146 #if __cplusplus >= 201103L
147 template<
typename _Up,
typename... _Args>
149 construct(_Up* __p, _Args&&... __args)
150 noexcept(noexcept(::
new((
void *)__p)
151 _Up(std::forward<_Args>(__args)...)))
152 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
154 template<
typename _Up>
157 noexcept(noexcept(__p->~_Up()))
163 construct(pointer __p,
const _Tp& __val)
164 { ::new((
void *)__p) value_type(__val); }
167 destroy(pointer __p) { __p->~_Tp(); }
171 template<
typename _Up>
172 friend _GLIBCXX20_CONSTEXPR
bool
177 template<
typename _Up>
178 friend _GLIBCXX20_CONSTEXPR
bool
184 _GLIBCXX_CONSTEXPR size_type
185 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
187 #if __PTRDIFF_MAX__ < __SIZE_MAX__
188 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
190 return std::size_t(-1) /
sizeof(_Tp);
195 _GLIBCXX_END_NAMESPACE_VERSION