std :: deque内存使用 - Visual C ++,以及与其他人的比较 [英] std::deque memory usage - Visual C++, and comparison to others
本文介绍了std :: deque内存使用 - Visual C ++,以及与其他人的比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Visual C ++使用以下内容根据容器元素类型管理 deque
块:
#define _DEQUESIZ(sizeof(value_type)< = 1?16 \
:sizeof(value_type)< = 2?8 \
:sizeof (value_type)<= 4?4 \
:sizeof(value_type)<= 8?2 \
:1)/ *每个块的元素(2的幂)* /
这会导致小型元素的内存占用量非常大。通过将第一行中的16更改为128,我可以大幅减少大量 deque< char>
所需的占用空间。进程浏览器私有字节从181MB下降到> 113MB,在100万 push_back(const char& mychar)
调用后)。
- 任何人都可以证明
中#define
的值是正确的? - 其他
编译器如何处理deque
block
sizing? - 对于100 m的简单
测试,它们的占用是
(32位操作)push_back
调用
deque< char>
? - STL允许
在
编译时覆盖此块大小,而不修改
&deque $ b $
$ breturn __size< 512? size_t(512 / __size):size_t(1);
注释
/ *'512'是
*可调(没有其他代码需要更改),但是没有调查
*,因为继承了SGI代码。
* /
Visual C++ manages
deque
blocks according to the container element type using this:#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) */
This results in very large memory footprint for small elements. By changing the 16 in the first line to 128 I was able to drastically reduce the footprint required for a large
deque<char>
. Process Explorer Private Bytes dropped from 181MB -> 113MB after 100mpush_back(const char& mychar)
calls).- Can anybody justify the values in
that
#define
? - How do other
compilers handle
deque
block sizing? - What would be their footprint
(32-bit operation) for the simple
test of 100m
push_back
calls todeque<char>
? - Does STL allow for
overriding of this block size at
compile-time, without modifying the
<deque>
code?
解决方案gcc has
return __size < 512 ? size_t(512 / __size) : size_t(1);
with a comment
/* The '512' is * tunable (and no other code needs to change), but no investigation has * been done since inheriting the SGI code. */
这篇关于std :: deque内存使用 - Visual C ++,以及与其他人的比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Can anybody justify the values in
that
查看全文