有没有办法得到deque的内部存储大小为vector :: capacity? [英] Is there a way to get deque's internal storage size as vector::capacity?
问题描述
我明白deque和vector都有一定的增长空间。 vector :: capacity()能够获得向量的内部保留空间。 Deque在标准中没有这样的成员。有没有办法获得这些信息?
I understand that both deque and vector reserve some space for growth. vector::capacity() is able to get the internal reserved space for a vector. Deque doesn't have such a member in the standard. Is there some way to get this information?
推荐答案
你必须深入到实现中去。 gcc 4.1.1附带的 std :: deque
的版本似乎以512字节的块分配内存。但是,只要我在15分钟后盯着所有的下划线和C风格的演员到 size_t
。然后我遇到了这个评论:
You'd have to dig into the implementation to figure that out. The version of std::deque
that comes with gcc 4.1.1 appears to allocate memory in 512 byte chunks. But that's as far as I got after 15 minutes of staring at all the underscores and C-style casts to size_t
. And then I came across this comment:
初始底层内存布局有点复杂...
The initial underlying memory layout is a bit complicated...
这篇关于有没有办法得到deque的内部存储大小为vector :: capacity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!