File.AppendAllText
最初にメモリ ストリームに書き込み、次にファイルにコピーするのではなく、ログ記録がどのように実行されるかを確認するために、いくつかのテストを実行していました。だから、メモリ操作がどれほど速いかを見るために、これをやった..
private void button1_Click(object sender, EventArgs e)
{
using (var memFile = new System.IO.MemoryStream())
{
using (var bw = new System.IO.BinaryWriter(memFile))
{
for (int i = 0; i < Int32.MaxValue; i++)
{
bw.Write(i.ToString() + Environment.NewLine);
}
bw.Flush();
}
memFile.CopyTo(new System.IO.FileStream(System.IO.Path.Combine("C", "memWriteWithBinaryTest.log"), System.IO.FileMode.OpenOrCreate));
}
}
i
到達する25413324
とException of type 'System.OutOfMemoryException' was thrown.
、Process Explorerには約 700Mb の空き RAM があると表示されますが、
ここにスクリーンショットがあります(念のため)
プロセス エクスプローラー
これがウィンフォームです
編集:ヒープ上に作成されるオブジェクトを増やすために、これに書き直しましbw.write
た
bw.Write(i);