title: Dynamically allocating multiple big arrays in C
body: <p>I'm writing a program in C on windows that launches 30 threads, each of which needs an array of <code>int16_t</code>.</p>
  
  <p>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.</p>
  
  <p>I've tried using both <code>malloc</code> and <code>calloc</code> inside the thread function, but over half of the allocations return NULL with <code>errno</code> set to 12 (<code>enomem</code>).</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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?</p>