29#ifndef _MALLOC_ALLOCATOR_H
30#define _MALLOC_ALLOCATOR_H 1
39#if __cplusplus >= 201103L
43namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
55 template<
typename _Tp>
59 typedef _Tp value_type;
60 typedef std::size_t size_type;
61 typedef std::ptrdiff_t difference_type;
62#if __cplusplus <= 201703L
64 typedef const _Tp* const_pointer;
65 typedef _Tp& reference;
66 typedef const _Tp& const_reference;
68 template<
typename _Tp1>
73#if __cplusplus >= 201103L
85 template<
typename _Tp1>
88 _GLIBCXX_USE_NOEXCEPT { }
90#if __cplusplus <= 201703L
94 address(reference __x)
const _GLIBCXX_NOEXCEPT
98 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
104 _GLIBCXX_NODISCARD _Tp*
105 allocate(size_type __n,
const void* = 0)
107#if __cplusplus >= 201103L
110 static_assert(
sizeof(_Tp) != 0,
"cannot allocate incomplete types");
113 if (__builtin_expect(__n > this->_M_max_size(),
false))
117 if (__n > (std::size_t(-1) /
sizeof(_Tp)))
118 std::__throw_bad_array_new_length();
119 std::__throw_bad_alloc();
124#if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC
125 if (
alignof(_Tp) >
alignof(std::max_align_t))
127 __ret =
static_cast<_Tp*
>(::aligned_alloc(
alignof(_Tp),
131# define _GLIBCXX_CHECK_MALLOC_RESULT
135 __ret =
static_cast<_Tp*
>(std::malloc(__n *
sizeof(_Tp)));
137 std::__throw_bad_alloc();
138#ifdef _GLIBCXX_CHECK_MALLOC_RESULT
139#undef _GLIBCXX_CHECK_MALLOC_RESULT
140 if (
reinterpret_cast<std::size_t
>(__ret) %
alignof(_Tp))
143 deallocate(__ret, __n);
144 std::__throw_bad_alloc();
152 deallocate(_Tp* __p, size_type)
153 { std::free(
static_cast<void*
>(__p)); }
155#if __cplusplus <= 201703L
157 max_size()
const _GLIBCXX_USE_NOEXCEPT
158 {
return _M_max_size(); }
160#if __cplusplus >= 201103L
161 template<
typename _Up,
typename... _Args>
163 construct(_Up* __p, _Args&&... __args)
165 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
167 template<
typename _Up>
176 construct(pointer __p,
const _Tp& __val)
177 { ::new((
void *)__p) value_type(__val); }
180 destroy(pointer __p) { __p->~_Tp(); }
184 template<
typename _Up>
185 friend _GLIBCXX20_CONSTEXPR
bool
190#if __cpp_impl_three_way_comparison < 201907L
191 template<
typename _Up>
192 friend _GLIBCXX20_CONSTEXPR
bool
199 _GLIBCXX_CONSTEXPR size_type
200 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
202#if __PTRDIFF_MAX__ < __SIZE_MAX__
203 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
205 return std::size_t(-1) /
sizeof(_Tp);
210_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.