C# - How to Save IntPtr Buffer Data to File (quickest way)?
<p>I'm using this code to save bytes from a IntPtr buffer in unmanaged code to file. It's a simple callback function:</p>

<pre class="lang-cs prettyprint-override"><code>private void callback(IntPtr buffer, int length)
{
    byte[] bytes = new byte[length];
    Marshal.Copy(buffer, bytes, 0, length);
    FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write);
    file.Write(bytes, 0, length);
    file.Close();
}
</code></pre>

<p>What I want is to store this data to file and through it away. From what I understand there is a buffer in the unmanaged code and a 2nd one in MY code. I don't want to copy the data around I want it directly:</p>

<pre class="lang-cs prettyprint-override"><code>// bad:     buffer -&gt; bytes -&gt; file
// awesome: buffer -&gt;          file
</code></pre>

<p>For my task I need the most quickest way to store the data to file.</p>
