When using the vector "From memory" is displayed.
To fix this, I use max_size () to check, then backup or push_back.
If max_size () is greater than the reserved value, this should be fine, but it is not! Then what is the value of max_size ()?
I am compiling the below demo in Windows 7 and Visual Studio 2010. My computer has 4 GB of RAM. When reseverd is 1/2 of max_size (), it fails.
max_size()=2^32/sizeof(CPoint3D)-1=268435455
This is normal when 1/4 of max_size () in the demo. In my real project, this is normal to 1/10.
What is the right maximum size of a vector, how to increase it ?
I got a "out of memory" error when I push a lot of elements in std::vector . To avoid the error, I first checked with vector::max_size() and used vector::reserve() to preallocate memory. However, this does not work. In a demo project, an error occurs when I reserve 1/4 of max_size . In a real project, an error occurs when I reserve 1/10. I am running Windows 7 and compiling with Visual Studio 2010. My computer has 4 GB of RAM.
If max_size does not work, how can I find out the maximum number of elements that I can allocate for vector ?
liwen zeng
source share