richard.g
richard.g

Reputation: 3765

The memory cost of a hash_map structure in C++ STL

In order to use hash_map, I assume that a consecutive memory block will be allocated, but what's the size of this block by default?

Upvotes: 1

Views: 551

Answers (2)

Tony Delroy
Tony Delroy

Reputation: 106068

This following is for unordered_map - the name for the hash map in C++11 onwards...

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. Gives you a bit of a feel for things....

You can also call .bucket_count() to get the instantaneous count.

Upvotes: 1

Pratik Roy
Pratik Roy

Reputation: 117

The size of each block will depend on the implementation .

e.g. your hash map declaration is : 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.

Upvotes: 0

Related Questions