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
56 template<
typename _Tp>
57 class malloc_allocator
60 typedef size_t size_type;
61 typedef ptrdiff_t difference_type;
63 typedef const _Tp* const_pointer;
64 typedef _Tp& reference;
65 typedef const _Tp& const_reference;
66 typedef _Tp value_type;
68 template<
typename _Tp1>
70 {
typedef malloc_allocator<_Tp1> other; };
72 #if __cplusplus >= 201103L 79 malloc_allocator() _GLIBCXX_USE_NOEXCEPT { }
82 malloc_allocator(
const malloc_allocator&) _GLIBCXX_USE_NOEXCEPT { }
84 template<
typename _Tp1>
86 malloc_allocator(
const malloc_allocator<_Tp1>&)
87 _GLIBCXX_USE_NOEXCEPT { }
89 ~malloc_allocator() _GLIBCXX_USE_NOEXCEPT { }
92 address(reference __x)
const _GLIBCXX_NOEXCEPT
96 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
102 allocate(size_type __n,
const void* = 0)
104 if (__n > this->max_size())
105 std::__throw_bad_alloc();
108 #if __cpp_aligned_new 109 #if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC 110 if (
alignof(_Tp) >
alignof(std::max_align_t))
112 __ret =
static_cast<_Tp*
>(::aligned_alloc(
alignof(_Tp),
116 # define _GLIBCXX_CHECK_MALLOC_RESULT 120 __ret =
static_cast<_Tp*
>(std::malloc(__n *
sizeof(_Tp)));
122 std::__throw_bad_alloc();
123 #ifdef _GLIBCXX_CHECK_MALLOC_RESULT 124 #undef _GLIBCXX_CHECK_MALLOC_RESULT 125 if (reinterpret_cast<std::size_t>(__ret) %
alignof(_Tp))
128 deallocate(__ret, __n);
129 std::__throw_bad_alloc();
137 deallocate(pointer __p, size_type)
138 { std::free(static_cast<void*>(__p)); }
141 max_size() const _GLIBCXX_USE_NOEXCEPT
143 #if __PTRDIFF_MAX__ < __SIZE_MAX__ 144 return size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
146 return size_t(-1) /
sizeof(_Tp);
150 #if __cplusplus >= 201103L 151 template<
typename _Up,
typename... _Args>
153 construct(_Up* __p, _Args&&... __args)
154 noexcept(noexcept(::
new((
void *)__p)
155 _Up(std::forward<_Args>(__args)...)))
156 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
158 template<
typename _Up>
161 noexcept(noexcept(__p->~_Up()))
167 construct(pointer __p,
const _Tp& __val)
168 { ::new((
void *)__p) value_type(__val); }
171 destroy(pointer __p) { __p->~_Tp(); }
174 template<
typename _Up>
176 operator==(
const malloc_allocator&,
const malloc_allocator<_Up>&)
180 template<
typename _Up>
182 operator!=(
const malloc_allocator&,
const malloc_allocator<_Up>&)
187 _GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
GNU extensions for public use.