On 32 bit System.
std::vector<char>::max_size()
returns 232-1, size of char
— 1 bytestd::vector<int>::max_size()
returns 230-1, size of int
— 4 bytestd::vector<double>::max_size()
returns 229-1, size of double
— 8 bytecan anyone tell me max_size()
depends on what?
and what will be the return value of max_size()
if it runs on 64 bit system.
Simply get the answer by
std::vector<dataType> v;
std::cout << v.max_size();
Or we can get the answer by (2^nativePointerBitWidth)/sizeof(dataType) - 1
. For example, on a 64 bit system, long long
is (typically) 8 bytes wide, so we have (2^64)/8 - 1 == 2305843009213693951
.