title: How to dynamically expand a Memory Mapped File
body: <p>I've used C# to solve the following requirement..
  - create an app the can receive a lot of data fast
  - you must be able to analyse the received data while more are incoming.
  - use as little CPU and disk as possible</p>
  
  <p>My idea for an algorithm was..</p>
  
  <pre><code>SIZE = 10MB
  Create a mmf with the size of SIZE
  On data recived:
    if data can't fit mmf: increase mmf.size by SIZE
    write the data to mmf
  </code></pre>
  
  <p>-> The size on the disc are increased in chuncks of 10MB when the previous "room/space" are used.</p>
  
  <p>How is the "increase mmf.size by SIZE" done in C#? I have found a lot of simple examples on creating mmfs and views but the only place (<a href="http://www.developer.com/net/article.php/10916_3828586_4/Using-Memory-Mapped-Files-in-NET-40.htm" rel="noreferrer">link</a>) I have seen code that acutally increases the mmfs area uses code that can't compile. Any help will be greatly appriciated.</p>
  
  <p>EDIT
  This causes an exception :</p>
  
  <pre><code>private void IncreaseFileSize()
  {
      int theNewMax = this.currentMax + INCREMENT_SIZE;
      this.currentMax = theNewMax;
  
      this.mmf.Dispose();
  
      this.mmf = MemoryMappedFile.CreateFromFile(this.FileName, FileMode.Create, "MyMMF", theNewMax);
      this.view = mmf.CreateViewAccessor(0, theNewMax);            
  }
  </code></pre>
  
  <p>This exception is thrown : The process cannot access the file 'C:\Users\moberg\Documents\data.bin' because it is being used by another process.</p>