How to know the right max size of vector? max_size()? but no

前端 未结 4 531
不思量自难忘°
不思量自难忘° 2021-01-15 15:59

When using vector, \"Out of Memory\" show.
To fix it, I use max_size() to check, then reserve or push_back.
If the max_size() is bigger the reserved value, it should

4条回答
  •  迷失自我
    2021-01-15 16:31

    vector::capacity() gives the maximum number of elements that can be stored in the vector without having a re-allocation, one which can potentially fail from std::bad_alloc.

    vector::max_size() has a different meaning, roughly similar to (INT_MAX / sizeof(element)).

    For more information on Windows memory management, see the MSDN article

提交回复
热议问题