mmirzadeh
mmirzadeh

Reputation: 7089

unordered_map max_size

I am using std::unordered_map and was trying to get the memory consumption so I did the following:

#include <iostream>
#include <unordered_map>

using namespace std;

int main(){
    unordered_map<int, int> map;
    map[21] = 12;

    cout << map.size() << endl << map.max_size() << endl;

    return 0;
}

to which the result is:

1
1152921504606846975

the first one is correct, what the heck is the second one?!

Upvotes: 4

Views: 3480

Answers (4)

neciu
neciu

Reputation: 4495

Check cppreference: link

map::max_size

Return maximum size

Returns the maximum number of elements that the map container object can hold.

This is the maximum potential size the container can reach due to system or library implementation limitations.

Upvotes: 2

NPE
NPE

Reputation: 500933

It's an upper bound on the maximum number of elements the container could potentially hold.

Upvotes: 1

Johan Lundberg
Johan Lundberg

Reputation: 27078

max_size()

Returns the maximum number of elements that the map container object can hold.

Upvotes: 1

Alok Save
Alok Save

Reputation: 206646

map.max_size() 

Returns the maximum potential size the container can reach due to system or library implementation limitations.


map.size() 

Returns the number of elements in the container.

Upvotes: 4

Related Questions