What is the maximum size of an vector ....
I think you have answered your own question.
Theoretical limit for your system you can get with a function vector<T>::max_size()
. For instance:
vector<int> vec;
std::cout<<vec.max_size()<<std::endl;//prints max size for vector<int> in your system!
So just run this and check out the answer for your system.
However in practice the vector's allocated array must be in one consecutive memory block and even with less size memory allocation can fail. If you are going to use vector of ints with million elements I think you shouldn't have any problems. However for bigger objects it can be problematic.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…