title: fread buffer size - I've loads of memory so why not make it huge?
body: <p>Ok I haven`t the benefit of having studied computer science so this may be an easy question to those that have. 
  Basically as the title says What is stopping me from creating a massive buffer, much bigger than the file size to use with the fread() function. 
  As I understand it fread() will return the total number of elements successfully read so at that point I could just realloc the buffer back to the file size.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  int main () {
      FILE * pFile;
      long lSize;
      char * buffer = NULL;
      size_t result = 0;
      pFile = fopen ( "test.txt" , "r" );
      if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
  
  // memory is cheap!! size:
      lSize = 1000000;
      buffer = (char*) realloc(buffer, (sizeof(char) * lSize));
      if (buffer)
      {
          result += fread(buffer, sizeof(char), 1, pFile);
      }
  // copy the file into the buffer:
      result = fread (buffer,1,lSize,pFile);
  
  /* file is now loaded in the memory buffer. Now resize buffer    */
      buffer = (char*) realloc(buffer, (sizeof(char) * result));
  
  // tidy up
      printf("\n%s",buffer);
      free(buffer);
      fclose (pFile);
      return 0;
   }
  </code></pre>
  
  <p>This is just a sample of what I'm talking about. I'm presuming that the file size is &lt; buffer size </p>