Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum size of the map object in c++ and java?

Tags:

java

c++

hashmap

What is the maximum size of hashmap/map object in c++ and java? I want to use hashmap, but i am working on huge data. I am worrying if i use this on large data, it may crash because of its capacity limit. Is that so? If so, what can be the alternative way?

like image 465
user1061293 Avatar asked Dec 20 '11 17:12

user1061293


1 Answers

In Java, the size() of a HashMap is of type int, so there's an upper bound of 2^31-1 elements in the map.

In C++, map::max_size returns the max. number of elements. In a vanilla map, there's an upper bound of at most SIZE_T_MAX elements, which is 2^64-1 on modern hardware.

like image 104
Fred Foo Avatar answered Sep 18 '22 14:09

Fred Foo