Reputation: 1447
What is maximum size of std::size and std::map? And is there a way to increase this number?
Thanks!
Upvotes: 4
Views: 5067
Reputation: 320531
Maximum size of any standard container is given by container<T>::max_size()
method. In general case, this size might (and will) be smaller than the range of container<T>::size_type
.
The range of container::size_type
can be obtained through std::numeric_limits
, but, again, keep in mind that containers do not guarantee that their maximum size can reach the full range of their size_type
.
Note also that container<T>::max_size()
returns the maximum number of elements in the container, while std::numeric_limits<container<T>::size_type>::max()
returns the range of the size_type
. These are incomparable values.
Upvotes: 3
Reputation: 9029
You can get maximum size of every standard library container by calling Container::max_size()
on it. If you need theoretical maximum size value at compile time, use std::numeric_limits<Container::size_type>::max()
.
Upvotes: 4
Reputation: 9089
Theoretical limit is maximal number that size_t
could contain which is typically used to return number of elements in container. For most 32 bit platforms its 2^32, for most 64 bit platforms its 2^64, but actually this is implementation defined, there are no strong restrictions in standard.
But practically the possible maximal size of any container is much less because it is limited by available memory address space and by available free memory.
Upvotes: 1