I need to allocate a fairly large chunk (or chunks) of memory - several gigabytes. But if I try to allocate a float array of more than 532000000 elements(~2 Gb), I get a runtime error:
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
This is ok:
float* d = new float[532000000];
But this is bad (bad_alloc exception):
float* d = new float[533000000];
Then I tried to allocate another array in addition to the first. It was found that the maximum size of second float array is 195000000 elements (~748 Mb).
This is ok:
float* d = new float[532000000];
float* e = new float[196000000];
This is bad:
float* d = new float[532000000];
float* e = new float[197000000];
I would like to know what are the limitations to the allocated memory in an application and how to avoid them? How can use virtual memory?
My system - 32-bit ubuntu 12.10, compiler - gcc 4.7, RAM - 8GB (~6.5 Gb free)