title: Why is malloc not "using up" the memory on my computer?
body: <p>So I have this program that allocates 256 MB of memory, and after the user presses ENTER it frees the memory and terminates.      </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void) {
      char *p, s[2];
  
      p = malloc(256 * 1024 * 1024);
      if ( p == NULL) 
          exit(1);
  
      printf("Allocated"); 
      fgets(s, 2, stdin);
      free(p);
      return 0;
  }
  </code></pre>
  
  <p>I ran this program multiple times and backgrounded each of them until there is no longer enough memory that can be allocated. However, that never happens. I ran a linux <code>top</code> command and even after running this program many times, the free memory never goes down by nearly as much as 256 MB. </p>
  
  <p>However, on the other hand, if I use <code>calloc</code> instead of <code>malloc</code> then there is a HUGE difference: </p>
  
  <p><code>p = calloc(256 * 1024 * 1024, 1);</code></p>
  
  <p>Now if I run the program and background it, and repeat, every time I run it, the free memory goes down by 256 MB. Why is this? Why does <code>malloc</code> not cause the available free memory to change, but <code>calloc</code> does? </p>