简体   繁体   English

如何查找STL hash_map的表大小和内存消耗?

[英]How to find table size and memory consumption of STL hash_map?

I want to know how stl hash_map is implemented. 我想知道stl hash_map是如何实现的。 How do I find out what the table size is and the memory space the map consumes? 我如何找出表的大小和映射占用的内存空间? This is in C++. 这是在C ++中。

There is no such thing as an "stl hash_map". 没有“ stl hash_map”这样的东西。 There is an unordered_map in TR1, but I assume you're not using that or you would have said unordered_map. TR1中有一个unordered_map,但我认为您没有使用它,否则您会说unordered_map。

As someone pointed out, unordered_map has "bucket_count" to determine the number of buckets. 正如有人指出的那样,unordered_map具有“ bucket_count”来确定存储桶的数量。 You can iterate over each bucket, get it's size ("bucket_size(size_t bucket_num)"), multiply that by the size of a pair of key and values, and add them all up to give you a rough estimate of the memory used. 您可以遍历每个存储桶,获取其大小(“ bucket_size(size_t bucket_num)”),然后将其乘以一对键和值的大小,然后将它们全部相加,以大致估算出所使用的内存。 There may be non-portable ways which are implementation defined. 可能有实现定义的非便携式方式。 It will obviously be implemention defined for whatever hash_map class you're using. 显然,它将为您使用的任何hash_map类定义实现。

This blog entry on C++ STL Hash Containers and Performance is a good looking explanation of STL hash map. 有关C ++ STL哈希容器和性能的博客条目很好地解释了STL哈希图。 See if it helps you. 看看是否对您有帮助。

尝试bucket_count

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

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