I need to allocate memory for 808704000 floats, which is something like 3085 MB. My computer has 32 GB of memory, and runs 64 bit Linux (CentOS 6.6). Every time I try to allocate the memory the malloc operation fails. I use g++ 4.4.7.
Can anyone explain why I cannot allocate the memory? Is it possible to somehow force the program to be compiled in 64 bit mode?
void AllocateMemory(float *& pointer, int size, void** pointers,
int& Npointers, nifti_image** niftiImages,
int Nimages, const char* variable)
{
pointer = (float*)malloc(size);
if (pointer != NULL)
{
pointers[Npointers] = (void*)pointer;
Npointers++;
}
else
{
printf("Could not allocate host memory for variable %s !\n",
variable);
FreeAllMemory(pointers, Npointers);
FreeAllNiftiImages(niftiImages, Nimages);
exit(EXIT_FAILURE);
}
}
ulimit -a
prints:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 256261
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) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 1024
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited