diff options
author | Dhruv Matani <dhruvbird@gmx.net> | 2004-02-04 17:37:10 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2004-02-04 17:37:10 +0000 |
commit | 56766e0db52fc71287838c62892fec2092a039b7 (patch) | |
tree | 2e61646b825698160302b8a9fd9671eda0d261b8 | |
parent | 7bdff56f69a0192ec53594c6ff40e4646874041e (diff) | |
download | gcc-56766e0db52fc71287838c62892fec2092a039b7.zip gcc-56766e0db52fc71287838c62892fec2092a039b7.tar.gz gcc-56766e0db52fc71287838c62892fec2092a039b7.tar.bz2 |
debug_allocator.h: _M_extra now stands for the number of extra objects instead of the number of...
2004-02-04 Dhruv Matani <dhruvbird@gmx.net>
* include/ext/debug_allocator.h: _M_extra now stands for the
number of extra objects instead of the number of extra bytes.
(debug_allocator::allocate): Adjust.
(debug_allocator::deallocate): Adjust.
* include/ext/pool_allocator.h: Fix typo.
From-SVN: r77256
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/debug_allocator.h | 36 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/pool_allocator.h | 2 |
3 files changed, 35 insertions, 12 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6921ac1..c4963b7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2004-02-04 Dhruv Matani <dhruvbird@gmx.net> + + * include/ext/debug_allocator.h: _M_extra now stands for the + number of extra objects instead of the number of extra bytes. + (debug_allocator::allocate): Adjust. + (debug_allocator::deallocate): Adjust. + + * include/ext/pool_allocator.h: Fix typo. + 2004-02-03 Felix Yen <fwy@alumni.brown.edu> Benjamin Kosnik <bkoz@redhat.com> diff --git a/libstdc++-v3/include/ext/debug_allocator.h b/libstdc++-v3/include/ext/debug_allocator.h index e744ab6..eb87680 100644 --- a/libstdc++-v3/include/ext/debug_allocator.h +++ b/libstdc++-v3/include/ext/debug_allocator.h @@ -1,6 +1,6 @@ // Allocators -*- C++ -*- -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -48,7 +48,7 @@ #ifndef _DEBUG_ALLOCATOR_H #define _DEBUG_ALLOCATOR_H 1 -#include <memory> +#include <cstdlib> namespace __gnu_cxx { @@ -74,28 +74,42 @@ namespace __gnu_cxx 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; + // _M_extra is the number of objects that correspond to the + // extra space where debug information is stored. + size_type _M_extra; _Alloc _M_allocator; public: - debug_allocator() : _M_extra(8) { } + debug_allocator() + { + const size_t __obj_size = sizeof(value_type); + _M_extra = (sizeof(size_type) + __obj_size - 1) / __obj_size; + } + + pointer + allocate(size_type __n) + { + pointer __res = _M_allocator.allocate(__n + _M_extra); + size_type* __ps = reinterpret_cast<size_type*>(__res); + *__ps = __n; + return __res + _M_extra; + } pointer - allocate(size_type __n, std::allocator<void>::const_pointer = 0) + allocate(size_type __n, const void* __hint) { - pointer __result = _M_allocator.allocate(__n + _M_extra); - *__result = __n; - return __result + _M_extra; + pointer __res = _M_allocator.allocate(__n + _M_extra, __hint); + size_type* __ps = reinterpret_cast<size_type*>(__res); + *__ps = __n; + return __res + _M_extra; } void deallocate(pointer __p, size_type __n) { pointer __real_p = __p - _M_extra; - if (*__real_p != __n) + if (*reinterpret_cast<size_type*>(__real_p) != __n) abort(); _M_allocator.deallocate(__real_p, __n + _M_extra); } diff --git a/libstdc++-v3/include/ext/pool_allocator.h b/libstdc++-v3/include/ext/pool_allocator.h index 2893890..b6bd423 100644 --- a/libstdc++-v3/include/ext/pool_allocator.h +++ b/libstdc++-v3/include/ext/pool_allocator.h @@ -40,7 +40,7 @@ * purpose. It is provided "as is" without express or implied warranty. */ -/** @file ext/debug_allocator.h +/** @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. */ |