gpt4 book ai didi

c++ - std::deque 内存使用 - Visual C++,以及与其他人的比较

转载 作者:IT老高 更新时间:2023-10-28 22:05:09 26 4
gpt4 key购买 nike

关注 What the heque is going on with the memory overhead of std::deque?

Visual C++ 管理deque根据容器元素类型使用此 block :

#define _DEQUESIZ   (sizeof (value_type) <= 1 ? 16 \
: sizeof (value_type) <= 2 ? 8 \
: sizeof (value_type) <= 4 ? 4 \
: sizeof (value_type) <= 8 ? 2 \
: 1) /* elements per block (a power of 2) */

这会导致小元素占用大量内存。通过将第一行中的 16 更改为 128,我能够大大减少大型 deque<char> 所需的占用空间。 . Process Explorer Private Bytes 在 100m push_back(const char& mychar) 后从 181MB -> 113MB 下降电话)。

  • 任何人都可以证明那#define ?
  • 其他的怎么办编译器处理 deque堵塞浆纱?
  • 他们的足迹是什么(32位操作)为简单100m测试push_back呼吁 deque<char> ?
  • STL 是否允许覆盖此 block 大小编译时,无需修改 <deque>代码?

最佳答案

gcc 有

return __size < 512 ? size_t(512 / __size) : size_t(1);

有评论

/*  The '512' is
* tunable (and no other code needs to change), but no investigation has
* been done since inheriting the SGI code.
*/

关于c++ - std::deque 内存使用 - Visual C++,以及与其他人的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4097729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com