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

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

    The problem is that vector tries to allocate a contiguous block of memory, which might not be available at that time, even though the total available memory may be much larger.

    I would suggest to use std::deque as it does not require to allocate a contiguous block of memory.

提交回复
热议问题