I was looking at std::string::max_size and noticed the example:
#include <iostream>
#include <string>
int main ()
{
std::string str ("Test string");
std::cout << "max_size: " << str.max_size() << "\n";
return 0;
}
with the output:
max_size: 4294967291
However, I always thought this limitation is due to the max value of an unsigned integer / size_t - so I kind of expected it to be 2^32 - 1
which would be 4294967295
. Why is the max size in this example not using those 4 bytes?
I also tried to run the sample code, and on that machine it was 2^62
- which again confused me, why wouldn't it be 2^64 - 1
instead?
In general I am wondering, for what reasons would an implementation not use all the space?