June 10th, 2009, 03:46 PM
VS 2008, C++ std::bad_alloc at just 133 mb
I am running following code, trying to see how much max memory can i allocate
unsigned long* ptr;
for(unsigned long i=0; i<1000000000; i++) //1 billion
ptr = new unsigned long(0);
catch( bad_alloc &ba)
I get bad_alloc exception at i=33401936, consider unsigned long takes 4 bytes, it is running out of memory at approx 133mb. However 32 bit address space should support up to 2GB. I have a 4GB ram so it should suffice and task manager says 2.5/4 GB is free.
I am using VS2008 on windows 7. Can anybody comment why is it failing at 133mb only.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!