42 #ifndef _DEBUG_ALLOCATOR_H
43 #define _DEBUG_ALLOCATOR_H 1
47 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<
typename _Alloc>
65 typedef typename _Alloc::size_type size_type;
66 typedef typename _Alloc::difference_type difference_type;
67 typedef typename _Alloc::pointer pointer;
68 typedef typename _Alloc::const_pointer const_pointer;
69 typedef typename _Alloc::reference reference;
70 typedef typename _Alloc::const_reference const_reference;
71 typedef typename _Alloc::value_type value_type;
83 const size_t __obj_size =
sizeof(value_type);
84 _M_extra = (
sizeof(size_type) + __obj_size - 1) / __obj_size;
88 allocate(size_type __n)
90 pointer __res = _M_allocator.allocate(__n + _M_extra);
91 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
93 return __res + _M_extra;
97 allocate(size_type __n,
const void* __hint)
99 pointer __res = _M_allocator.allocate(__n + _M_extra, __hint);
100 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
102 return __res + _M_extra;
106 deallocate(pointer __p, size_type __n)
110 pointer __real_p = __p - _M_extra;
111 if (*reinterpret_cast<size_type*>(__real_p) != __n)
113 throw std::runtime_error(
"debug_allocator::deallocate"
116 _M_allocator.deallocate(__real_p, __n + _M_extra);
119 throw std::runtime_error(
"debug_allocator::deallocate null pointer");
123 _GLIBCXX_END_NAMESPACE_VERSION
GNU extensions for public use.
A meta-allocator with debugging bits, as per [20.4].This is precisely the allocator defined in the C+...