title: Determining buffer size when working with files in C#?
body: <p>I have this simple code which combines text files into one text file : </p>
  
  <pre><code>void Main()
  {
  const int chunkSize = 2 * 1024; // 2KB
  var inputFiles = new[] { @"c:\1.txt", @"c:\2.txt", @"c:\3.txt" };
  using (var output = File.Create(@"c:\output.dat"))
  {
      foreach (var file in inputFiles)
      {
          using (var input = File.OpenRead(file))
          {
              var buffer = new byte[chunkSize];
              int bytesRead;
              while ((bytesRead = input.Read(buffer, 0, buffer.Length)) &gt; 0)
              {
                  output.Write(buffer, 0, bytesRead);
              }
          }
      }
  }
  }
  </code></pre>
  
  <p>My question is about the <code>chunkSize</code> size.</p>
  
  <p>How can I know if the number I've chosen is the right one ? (1024*2)</p>
  
  <p>I'm trying to find the idle formula : </p>
  
  <p>Assuming each file size is <code>F mb</code> , and I have <code>R mb</code> of Ram and the block size of my Hd is <code>B kb</code> - is there any formula which I can build to find the idle buffer size ? </p>