简体   繁体   English

C ++ STL中hash_map结构的内存成本

[英]The memory cost of a hash_map structure in C++ STL

为了使用hash_map,我假设将分配一个连续的内存块,但是默认情况下该块的大小是多少?

This following is for unordered_map - the name for the hash map in C++11 onwards... 以下是unordered_map -从C ++ 11开始的哈希图的名称...

While the initial size is implementation specific, the default .max_load_factor() is stipulated by the Standard to be 1.0 , so in general the number of buckets will only automatically increase when .size() becomes greater. 尽管初始大小是特定于实现的,但标准将默认的.max_load_factor()设置为1.0 ,因此通常,当.size()变大时,存储桶的数量只会自动增加。 Gives you a bit of a feel for things.... 给您一些事物的感觉。

You can also call .bucket_count() to get the instantaneous count. 您还可以调用.bucket_count()以获取瞬时计数。

The size of each block will depend on the implementation . 每个块的大小将取决于实现。

eg your hash map declaration is : hash_map homier; 例如,您的哈希映射声明为:hash_map homier;

Then the each hash block size will be = (bucket size of the string ) + (bucket size of the integer) as per the OS architecture. 然后,根据操作系统体系结构,每个哈希块大小将为=(字符串的桶大小)+(整数的桶大小)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM