Reputation: 22519
I want to know how stl hash_map is implemented. How do I find out what the table size is and the memory space the map consumes? This is in C++.
Upvotes: 1
Views: 1670
Reputation: 11981
There is no such thing as an "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.
As someone pointed out, unordered_map has "bucket_count" to determine the number of buckets. 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. There may be non-portable ways which are implementation defined. It will obviously be implemention defined for whatever hash_map class you're using.
Upvotes: 2
Reputation: 308763
This blog entry on C++ STL Hash Containers and Performance is a good looking explanation of STL hash map. See if it helps you.
Upvotes: 1