...似乎使用:_
::: <stl/_alloc.h>
...
enum { _MAX_BYTES = 32 * sizeof(void*) };
...
::: <deque>
...
static size_t _S_buffer_size()
{
const size_t blocksize = _MAX_BYTES;
return (sizeof(_Tp) < blocksize ? (blocksize / sizeof(_Tp)) : 1);
}
所以这意味着 32 x 4 = 128 字节块大小在 32 位和 32 x 8 = 256 字节块大小在 64 位。
我的想法:从大小开销 POV 来看,我想任何实现都可以使用可变长度块进行操作,但我认为这对于deque
.
至于问题
STL 是否允许在编译时覆盖此块大小而不修改代码?
这里也不可能。
(似乎是 Rogue Wave STL 版本)显然使用:
static size_type _C_bufsize () {
// deque only uses __rw_new_capacity to retrieve the minimum
// allocation amount; this may be specialized to provide a
// customized minimum amount
typedef deque<_TypeT, _Allocator> _RWDeque;
return _RWSTD_NEW_CAPACITY (_RWDeque, (const _RWDeque*)0, 0);
}
所以似乎有一些机制可以通过专门化覆盖块大小,并且 ... 的定义如下所示:
// returns a suggested new capacity for a container needing more space
template <class _Container>
inline _RWSTD_CONTAINER_SIZE_TYPE
__rw_new_capacity (_RWSTD_CONTAINER_SIZE_TYPE __size, const _Container*)
{
typedef _RWSTD_CONTAINER_SIZE_TYPE _RWSizeT;
const _RWSizeT __ratio = _RWSizeT ( (_RWSTD_NEW_CAPACITY_RATIO << 10)
/ _RWSTD_RATIO_DIVIDER);
const _RWSizeT __cap = (__size >> 10) * __ratio
+ (((__size & 0x3ff) * __ratio) >> 10);
return (__size += _RWSTD_MINIMUM_NEW_CAPACITY) > __cap ? __size : __cap;
}
所以我会说,嗯,很复杂。
(如果有人想进一步弄清楚这一点,请随时直接编辑我的答案或发表评论。)