What is the maximum size of an vector<>::maxsize()?

前端 未结 3 1449
庸人自扰
庸人自扰 2020-12-21 18:28

Please specify the range of vector list ....

I want to store million of records in vector<>.

I have to copy Millions of records from one vector<> to an

相关标签:
3条回答
  • 2020-12-21 18:47

    I test it in my pc. Windows 7 32bit. The result is 2^32/sizeof(CPoint3D)-1=268435455, sizeof(CPoint3D) is 16. But max_size is nothing. After it, m_point1.reserve(25641355), "Out of Memory" is showed.

    25641355 < 268435455

    0 讨论(0)
  • 2020-12-21 18:48

    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.

    0 讨论(0)
  • 2020-12-21 18:49

    There's no limit except the available memory. But: a vector requires all the memory to be in one consecutive memory area. If you want to store a million records, there might not be such a big memory area available.

    In that case, it's better to use a deque instead of a vector.

    0 讨论(0)
提交回复
热议问题