43 #ifndef _DEBUG_ALLOCATOR_H
44 #define _DEBUG_ALLOCATOR_H 1
60 template<typename _Alloc>
64 typedef typename _Alloc::size_type size_type;
65 typedef typename _Alloc::difference_type difference_type;
66 typedef typename _Alloc::pointer pointer;
67 typedef typename _Alloc::const_pointer const_pointer;
68 typedef typename _Alloc::reference reference;
69 typedef typename _Alloc::const_reference const_reference;
70 typedef typename _Alloc::value_type value_type;
82 const size_t __obj_size =
sizeof(value_type);
83 _M_extra = (
sizeof(size_type) + __obj_size - 1) / __obj_size;
87 allocate(size_type __n)
89 pointer __res = _M_allocator.allocate(__n + _M_extra);
90 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
92 return __res + _M_extra;
96 allocate(size_type __n,
const void* __hint)
98 pointer __res = _M_allocator.allocate(__n + _M_extra, __hint);
99 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
101 return __res + _M_extra;
105 deallocate(pointer __p, size_type __n)
109 pointer __real_p = __p - _M_extra;
110 if (*reinterpret_cast<size_type*>(__real_p) != __n)
112 throw std::runtime_error(
"debug_allocator::deallocate"
115 _M_allocator.deallocate(__real_p, __n + _M_extra);
118 throw std::runtime_error(
"debug_allocator::deallocate null pointer");
122 _GLIBCXX_END_NAMESPACE
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.
A meta-allocator with debugging bits, as per [20.4].This is precisely the allocator defined in the C+...