Is there a way to get deque's internal storage size as vector::capacity?

左心房为你撑大大i 提交于 2020-02-03 08:14:08

问题


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?


回答1:


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...




回答2:


Not portably. The reason there's no capacity member for deque is because it does not use contiguous memory. There's no reason, performance-wise, to consider it.



来源:https://stackoverflow.com/questions/3158379/is-there-a-way-to-get-deques-internal-storage-size-as-vectorcapacity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!