0

max_size() vs capacity in vector help confusion

i think max_size() give max number of element any vector can store & it will be constant for any vector. and capacity max number of element that depend upon numbeer of input or push_back operation.IN below code if i replace 100 by max_size()->4611686018427387903 then why it can't able to store the value since it has max_size(),and what is the use of max_size() if it is wrong // comparing size, capacity and max_size #include <iostream> #include <vector> int main () { std::vector<int> myvector; // set some content in the vector: for (int i=0; i<100; i++) myvector.push_back(i); std::cout << "size: " << myvector.size() << "\n"; std::cout << "capacity: " << myvector.capacity() << "\n"; std::cout << "max_size: " << myvector.max_size() << "\n"; return 0; }

23rd Jun 2018, 4:09 PM
Bahubali
Bahubali - avatar
5 Réponses
+ 2
Sincerally i think that its can be useful only on limited and reatricted system. Else i dont see any useful use with it (this is my opinion but someone can find a more useful use)
23rd Jun 2018, 4:36 PM
KrOW
KrOW - avatar
+ 1
max_size say you the POTENTIAL maximum that your vector can POSSIBLY store (depends on some factors which vector implementation) BUT this dont mean that you can reach this limit.
23rd Jun 2018, 4:21 PM
KrOW
KrOW - avatar
+ 1
thank u for helping me
23rd Jun 2018, 4:37 PM
Bahubali
Bahubali - avatar
+ 1
👍👍👍
23rd Jun 2018, 4:44 PM
KrOW
KrOW - avatar
0
so is there any use of it?or on my system it cant store
23rd Jun 2018, 4:26 PM
Bahubali
Bahubali - avatar