Commit e2aa7005 by Paolo Carlini Committed by Paolo Carlini

mt_allocator (__mt_alloc<>::_Tune): Add _M_align, the alignment requested.

2004-06-18  Paolo Carlini  <pcarlini@suse.de>

	* include/ext/mt_allocator (__mt_alloc<>::_Tune): Add _M_align,
	the alignment requested.
	(__mt_alloc<>::_Tune::_Tune): Tweak consistently.
	(__mt_alloc<>::allocate): Use it instead of sizeof(_Block_record).
	(__mt_alloc<>::deallocate): Likewise.

From-SVN: r83372
parent dc04f755
2004-06-18 Paolo Carlini <pcarlini@suse.de> 2004-06-18 Paolo Carlini <pcarlini@suse.de>
* include/ext/mt_allocator (__mt_alloc<>::_Tune): Add _M_align,
the alignment requested.
(__mt_alloc<>::_Tune::_Tune): Tweak consistently.
(__mt_alloc<>::allocate): Use it instead of sizeof(_Block_record).
(__mt_alloc<>::deallocate): Likewise.
2004-06-18 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/16020 PR libstdc++/16020
* include/debug/safe_base.h * include/debug/safe_base.h
(_Safe_sequence_base::_Safe_sequence_base(const _Safe_sequence_base&), (_Safe_sequence_base::_Safe_sequence_base(const _Safe_sequence_base&),
......
...@@ -118,12 +118,18 @@ namespace __gnu_cxx ...@@ -118,12 +118,18 @@ namespace __gnu_cxx
// assigned and explained in detail below. // assigned and explained in detail below.
struct _Tune struct _Tune
{ {
// Alignment needed.
// NB: In any case must be >= sizeof(_Block_record), that
// is 4 on 32 bit machines and 8 on 64 bit machines.
size_t _M_align;
// Allocation requests (after round-up to power of 2) below // Allocation requests (after round-up to power of 2) below
// this value will be handled by the allocator. A raw new/ // this value will be handled by the allocator. A raw new/
// call will be used for requests larger than this value. // call will be used for requests larger than this value.
size_t _M_max_bytes; size_t _M_max_bytes;
// Size in bytes of the smallest bin (must be a power of 2). // Size in bytes of the smallest bin.
// NB: Must be a power of 2 and >= _M_align.
size_t _M_min_bin; size_t _M_min_bin;
// In order to avoid fragmenting and minimize the number of // In order to avoid fragmenting and minimize the number of
...@@ -150,18 +156,19 @@ namespace __gnu_cxx ...@@ -150,18 +156,19 @@ namespace __gnu_cxx
explicit explicit
_Tune() _Tune()
: _M_max_bytes(128), _M_min_bin(8), : _M_align(8), _M_max_bytes(128), _M_min_bin(8),
_M_chunk_size(4096 - 4 * sizeof(void*)), _M_chunk_size(4096 - 4 * sizeof(void*)),
_M_max_threads(4096), _M_freelist_headroom(10), _M_max_threads(4096), _M_freelist_headroom(10),
_M_force_new(getenv("GLIBCXX_FORCE_NEW") ? true : false) _M_force_new(getenv("GLIBCXX_FORCE_NEW") ? true : false)
{ } { }
explicit explicit
_Tune(size_t __maxb, size_t __minbin, size_t __chunk, _Tune(size_t __align, size_t __maxb, size_t __minbin,
size_t __maxthreads, size_t __headroom, bool __force) size_t __chunk, size_t __maxthreads, size_t __headroom,
: _M_max_bytes(__maxb), _M_min_bin(__minbin), _M_chunk_size(__chunk), bool __force)
_M_max_threads(__maxthreads), _M_freelist_headroom(__headroom), : _M_align(__align), _M_max_bytes(__maxb), _M_min_bin(__minbin),
_M_force_new(__force) _M_chunk_size(__chunk), _M_max_threads(__maxthreads),
_M_freelist_headroom(__headroom), _M_force_new(__force)
{ } { }
}; };
...@@ -306,8 +313,10 @@ namespace __gnu_cxx ...@@ -306,8 +313,10 @@ namespace __gnu_cxx
_Block_record* __block = NULL; _Block_record* __block = NULL;
if (__bin._M_first[__thread_id] == NULL) if (__bin._M_first[__thread_id] == NULL)
{ {
// NB: For alignment reasons, we can't use the first _M_align
// bytes, even when sizeof(_Block_record) < _M_align.
const size_t __bin_size = ((_S_options._M_min_bin << __which) const size_t __bin_size = ((_S_options._M_min_bin << __which)
+ sizeof(_Block_record)); + _S_options._M_align);
size_t __block_count = _S_options._M_chunk_size / __bin_size; size_t __block_count = _S_options._M_chunk_size / __bin_size;
// Are we using threads? // Are we using threads?
...@@ -399,7 +408,7 @@ namespace __gnu_cxx ...@@ -399,7 +408,7 @@ namespace __gnu_cxx
} }
#endif #endif
char* __c = reinterpret_cast<char*>(__block) + sizeof(_Block_record); char* __c = reinterpret_cast<char*>(__block) + _S_options._M_align;
return static_cast<_Tp*>(static_cast<void*>(__c)); return static_cast<_Tp*>(static_cast<void*>(__c));
} }
...@@ -421,7 +430,7 @@ namespace __gnu_cxx ...@@ -421,7 +430,7 @@ namespace __gnu_cxx
const size_t __which = _S_binmap[__bytes]; const size_t __which = _S_binmap[__bytes];
const _Bin_record& __bin = _S_bin[__which]; const _Bin_record& __bin = _S_bin[__which];
char* __c = reinterpret_cast<char*>(__p) - sizeof(_Block_record); char* __c = reinterpret_cast<char*>(__p) - _S_options._M_align;
_Block_record* __block = reinterpret_cast<_Block_record*>(__c); _Block_record* __block = reinterpret_cast<_Block_record*>(__c);
#ifdef __GTHREADS #ifdef __GTHREADS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment