I need to dynamically allocate a larger float array for a special application using C++ new operator, like 10G. The code running on 64-ubuntu-14.04 Linux OS with 64G memory.
When I set the request of memory as about 7G ,1879048192x4/(1024x1024x1024)=7G
(float has 4 bytes), like this :
float * data;
data = new float[1879048192];
The program works well, but when I try to increase the request to 10G , I got a what(): std::bad_alloc
. I also try to use malloc()
to take place of new operator:
data =(float*)malloc(1879048192*sizeof(float));
But obtain the same result. My ulimit -a
is this:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 514689
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 514689
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Someone may say there might be no 10G continual memory for the allocation, but I close all other progresses and the total memory is 64G. I want to know whether I can obtain this larger array or not, and how. Does the Linux limit the max number for this dynamically allocation? Where and how?