g*********s 发帖数: 1782 | 1 【 以下文字转载自 Programming 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: Programming
标 题: STL map变量的实际memory usage估算
发信站: BBS 未名空间站 (Sat Apr 26 23:08:58 2008)
比如声明这样一个变量
using namespace std;
map *nameMap = new(map);
... // 在nameMap里插入了1000个(string, int) pair
现在需要估算这时heap的size增加了多少?
估算如下:
本身sizeof(map<...,...>)是48个字节。
一个string s的size是 sizeof(string) + s.size(),假定字符串长度都是8,则是16。
一个int是4字节。
这样至少是48+1000*(4+16)=2048 bytes。
但是map是用rb_tree实现,加上开销是多少呢?看了一下source code,不太确定是不
是算对了。
每个node包含c | T**********n 发帖数: 480 | 2 STL有自己的memory pool
用多少跟实际申请多少不见得对得上
【在 g*********s 的大作中提到】 : 【 以下文字转载自 Programming 讨论区 】 : 发信人: gandjmitbbs (Nothing), 信区: Programming : 标 题: STL map变量的实际memory usage估算 : 发信站: BBS 未名空间站 (Sat Apr 26 23:08:58 2008) : 比如声明这样一个变量 : using namespace std; : map *nameMap = new(map); : ... // 在nameMap里插入了1000个(string, int) pair : 现在需要估算这时heap的size增加了多少? : 估算如下:
|
|