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