This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
This patch makes the debug_allocator<> compile now. Earlier, the debug_allocator<> had code like this: size_type n; pointer x; *x = n; Which made no sense. -- -Dhruv Matani. http://www.geocities.com/dhruvbird/
Attachment:
changelog_debug_alloc
Description: Text document
*** debug_allocator.h_old Tue Feb 3 21:47:11 2004
--- debug_allocator.h Tue Feb 3 22:58:42 2004
***************
*** 48,54 ****
#ifndef _DEBUG_ALLOCATOR_H
#define _DEBUG_ALLOCATOR_H 1
! #include <memory>
namespace __gnu_cxx
{
--- 48,54 ----
#ifndef _DEBUG_ALLOCATOR_H
#define _DEBUG_ALLOCATOR_H 1
! #include <cstdlib>
namespace __gnu_cxx
{
*************** namespace __gnu_cxx
*** 74,103 ****
typedef typename _Alloc::value_type value_type;
private:
! // Size of space used to store size. Note that this must be
! // large enough to preserve alignment.
! const size_t _M_extra;
_Alloc _M_allocator;
public:
! debug_allocator() : _M_extra(8) { }
pointer
! allocate(size_type __n, std::allocator<void>::const_pointer = 0)
{
! pointer __result = _M_allocator.allocate(__n + _M_extra);
*__result = __n;
! return __result + _M_extra;
}
void
deallocate(pointer __p, size_type __n)
{
! pointer __real_p = __p - _M_extra;
if (*__real_p != __n)
abort();
! _M_allocator.deallocate(__real_p, __n + _M_extra);
}
};
} // namespace __gnu_cxx
--- 74,117 ----
typedef typename _Alloc::value_type value_type;
private:
! // _M_extra is the number of objects that the extra space
! // corresponds to.
! const size_type _M_extra;
_Alloc _M_allocator;
+ static size_type _S_num_objects (size_t _Extra_size, size_t _Obj_size)
+ {
+ return (_Extra_size + _Obj_size - 1) / _Obj_size;
+ }
+
public:
! debug_allocator() : _M_extra(_S_num_objects(8, sizeof(value_type))) { }
!
! pointer
! allocate(size_type __n)
! {
! size_type *__result = reinterpret_cast<size_type*>(_M_allocator.allocate(__n + _M_extra));
! *__result = __n;
! return reinterpret_cast<pointer>(__result) + _M_extra;
! }
pointer
! allocate(size_type __n, const void *__hint)
{
! size_type *__result = reinterpret_cast<size_type*>(_M_allocator.allocate(__n + _M_extra,
! __hint));
*__result = __n;
! return reinterpret_cast<pointer>(__result) + _M_extra;
}
void
deallocate(pointer __p, size_type __n)
{
! size_type *__real_p = __p - _M_extra;
if (*__real_p != __n)
abort();
! _M_allocator.deallocate(reinterpret_cast<pointer>(__real_p), __n + _M_extra);
}
};
} // namespace __gnu_cxx
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |