title: Array size based on available physical memory
body: <p>I am trying to make an encryption algorithm.
  I can read a file and convert it to bytes without any problems, and am saving the bytes in a byteArray.</p>
  
  <p>The problem is I am currently creating the array size like this:</p>
  
  <pre><code>byte[] FileArray =new byte[10000000];
  FileStream TheFileStream = new FileStream(FilePath.Text, FileMode.Open);
  BinaryReader TheFileBinary = new BinaryReader(TheFileStream);
  
  for (int i = 0; i &lt; TheFileStream.Length; i++) {
      FileArray = TheFileBinary.ReadBytes(10000000);
      // I call a function here
      if (TheFileStream.Position == TheFileStream.Length)
          break;
  }
  </code></pre>
  
  <p>However, I don't want the array size to be fixed, because if I make it 1000000 (as an example), other machines with small memory size might face a problem.
  I need to find the Idle size of a memory size for each machine, how can I set the array size dynamically based on the free unallocated memory space, to be used where I can put it in the byteArray?</p>
  
  <p>I have noticed the larger the Arraysize the faster it reads, so I don't want to make it too  small either.
  I would really appreciate the help.</p>