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

前端 未结 4 534
不思量自难忘°
不思量自难忘° 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:38

    max_size() tells you the design limit of the class, but memory shortage can limit the real size to something smaller. There's not generally any way to find what the lower limit might be though (e.g., it might change from one moment to another, depending on how much memory is used by other programs).

提交回复
热议问题