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
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.