30 #ifndef _MALLOC_ALLOCATOR_H
31 #define _MALLOC_ALLOCATOR_H 1
38 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
53 template<
typename _Tp>
57 typedef size_t size_type;
58 typedef ptrdiff_t difference_type;
60 typedef const _Tp* const_pointer;
61 typedef _Tp& reference;
62 typedef const _Tp& const_reference;
63 typedef _Tp value_type;
65 template<
typename _Tp1>
73 template<
typename _Tp1>
79 address(reference __x)
const {
return std::__addressof(__x); }
82 address(const_reference __x)
const {
return std::__addressof(__x); }
87 allocate(size_type __n,
const void* = 0)
89 if (__n > this->max_size())
90 std::__throw_bad_alloc();
92 pointer __ret =
static_cast<_Tp*
>(std::malloc(__n *
sizeof(_Tp)));
94 std::__throw_bad_alloc();
100 deallocate(pointer __p, size_type)
101 { std::free(static_cast<void*>(__p)); }
104 max_size()
const throw()
105 {
return size_t(-1) /
sizeof(_Tp); }
110 construct(pointer __p,
const _Tp& __val)
111 { ::new((
void *)__p) value_type(__val); }
113 #ifdef __GXX_EXPERIMENTAL_CXX0X__
114 template<
typename... _Args>
116 construct(pointer __p, _Args&&... __args)
117 { ::new((
void *)__p) _Tp(std::forward<_Args>(__args)...); }
121 destroy(pointer __p) { __p->~_Tp(); }
124 template<
typename _Tp>
129 template<
typename _Tp>
131 operator!=(
const malloc_allocator<_Tp>&,
const malloc_allocator<_Tp>&)
134 _GLIBCXX_END_NAMESPACE_VERSION
An allocator that uses malloc.This is precisely the allocator defined in the C++ Standard.