title: Why does a malloc of 2GB or larger of memory in the Heap in C fail?
body: <p>I want to allocate a specific size of memory on the C heap. As a test to do it I used the following piece of code (to check the maximum allowable value):</p>
  
  <pre><code>int main(void) {
     int *val;
     val=(int*)malloc(4096);
     if(!val)
        break;
     return 0;
  }
  </code></pre>
  
  <p>The problem is that when trying a range of values with <code>malloc()</code>, at about a size of 1900MB it fails. Yet I have 16 GB of installed RAM with about 12GB free.</p>
  
  <p>So I can't even think to allocate a higher value of memory.<br>
  Is there something that I'm doing wrong?<br>
  Is there something that I should know about <code>malloc()</code>?  </p>
  
  <p>I see many programs(like Virtual Machines)that use big amount of memory so i already ruled out the idea that is a security features of the OS.</p>