【发布时间】:2017-07-20 07:17:18
【问题描述】:
在下面给出的示例程序中(来源:http://www.cplusplus.com/reference/unordered_map/unordered_map/rehash/)
// unordered_map::rehash
#include <iostream>
#include <string>
#include <unordered_map>
int main ()
{
std::unordered_map<std::string,std::string> mymap;
mymap.rehash(20);
mymap["house"] = "maison";
mymap["apple"] = "pomme";
mymap["tree"] = "arbre";
mymap["book"] = "livre";
mymap["door"] = "porte";
mymap["grapefruit"] = "pamplemousse";
std::cout << "current bucket_count: " << mymap.bucket_count() << std::endl;
return 0;
}
输出变成:
current bucket_count: 23
为什么桶数变成 23?
对堆大小有什么影响?堆分配什么时候完成?在存储桶重新散列或实际插入时?动态释放何时完成?何时使用clear() 或erase() 或两者兼而有之?
【问题讨论】:
-
如果您提出一个问题并寻找该问题的答案,则此网站效果最佳。您在这里有大约 6 个问题。
标签: c++ heap-memory unordered-map dynamic-allocation g++4.9