I'm writing a program in C on windows that launches 30 threads, each of which needs an array of int16_t
.
The size is calculated before the thread function is called and in the example I'm working with it's around 250 millions. This is around 15GB, which should not be a problem, because I have 128GB ram available.
I've tried using both malloc
and calloc
inside the thread function, but over half of the allocations return NULL with errno
set to 12 (enomem
).
With a small number of threads (up to 3) it works fine though, same if I just use 1 thread and allocating an unreasonably big array.
My next attempt to solve this issue was to create an array of pointers in the main, allocate the arrays there and pass them as argument to the thread, same thing happened.
So from these results my best guess would be it can't allocate contiguous blocks of memory of that size, so I also tried allocating many smaller arrays, which obviously didn't work either. Is this an expected behaviour or am I doing something wrong?