This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch debug_allocator and pool_allocator.
- From: Dhruv Matani <dhruvbird at gmx dot net>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: 31 Jan 2004 16:51:46 +0530
- Subject: Patch debug_allocator and pool_allocator.
- Organization:
I think that this was the original intention of debug allocator.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
*** debug_allocator.h_old Sat Jan 31 16:27:42 2004
--- debug_allocator.h Sat Jan 31 16:47:29 2004
*************** namespace __gnu_cxx
*** 80,103 ****
_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
--- 80,110 ----
_Alloc _M_allocator;
+ size_type _Num_objects (size_t _Extra_size, size_t _Obj_size)
+ {
+ return (_Extra_size + _Obj_size - 1) / _Obj_size;
+ }
+
public:
debug_allocator() : _M_extra(8) { }
pointer
! allocate(size_type __n, const void *__hint = 0)
{
! size_type *__result = reinterpret_cast<size_type*>
! (_M_allocator.allocate(__n + _Num_objects (_M_extra, sizeof(value_type))));
*__result = __n;
! return reinterpret_cast<pointer>(reinterpret_cast<char*>(__result) + _M_extra);
}
void
deallocate(pointer __p, size_type __n)
{
! size_type *__real_p = reinterpret_cast<char*>(__p) - _M_extra;
if (*__real_p != __n)
abort();
! _M_allocator.deallocate(reinterpret_cast<pointer>(__real_p),
! __n + _Num_objects (_M_extra, sizeof(value_type)));
}
};
} // namespace __gnu_cxx
*** pool_allocator.h_old Sat Jan 31 16:27:57 2004
--- pool_allocator.h Sat Jan 31 16:46:18 2004
***************
*** 40,46 ****
* purpose. It is provided "as is" without express or implied warranty.
*/
! /** @file ext/debug_allocator.h
* This file is a GNU extension to the Standard C++ Library.
* You should only include this header if you are using GCC 3 or later.
*/
--- 40,46 ----
* purpose. It is provided "as is" without express or implied warranty.
*/
! /** @file ext/pool_allocator.h
* This file is a GNU extension to the Standard C++ Library.
* You should only include this header if you are using GCC 3 or later.
*/