title: Allocation of more than 2gb fails on 64 bit binary
body: <p>On a 64 bit linux machine I wrote the following small C program:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  int main (void)
  {
      #define BLOCK_SIZE (1024*1024)
      int i;
  
      for (i = 1; ; i++)
      {
          char *p = (char *)malloc(i * BLOCK_SIZE);
          if (p == 0)
              break;
          *p = 13;
          free(p);
      }
  
      printf ("Allocated max %d MB\n", (i - 1));
  
      return 0;
  }
  </code></pre>
  
  <p>If I compile this with <code>-O0 -m64</code>, I can allocate 2047 MB on my desktop system. If I compile the same program with <code>-O0 -m32</code> 3829 MB.</p>
  
  <p>Why is the maximal malloc size for a 32 bit binary larger than for a 64 bit binary on the same machine?</p>
  
  <p>Edit: If I activate the optimizer with <code>-O3</code>, the maximal amount of memory is 20588 on a 64 bit machine.</p>