title: How do I save a large F# array of records to file?
body: <p>I want to save a large f# array of records (> 10,000,000 elements) to disk so that it is easy to reload the array into memory later. I used the following simple function from Visual F# 2010 for technical computing: </p>
  
  <pre><code>let save filename x =
      use stream = new FileStream(filename, FileMode.Create)
      BinaryFormatter().Serialize(stream, x)
  
  type Test = { a : int; b : int}
  
  let x = [| for i in 1..6 do 
              let a=i
              let b=i*i
              yield {a=a;b=b}|]
  
  save "file.dat" x
  </code></pre>
  
  <p>When I do this (with the real data) I get the error:</p>
  
  <pre><code>System.Runtime.Serialization.SerializationException: The internal array cannot expand to greater than Int32.MaxValue elements.
  </code></pre>
  
  <p>Right now, my solution is to convert to Deedle and then save as a csv, but I presume that there is a more computationally efficient option for saving/reloading that does not require rebuilding the array from csv.</p>
  
  <pre><code>let x2 = x |&gt; Frame.ofRecords
  x2.SaveCsv("file.csv")
  </code></pre>