質問

ソケットストリームからディスクへのバイトをコピーする方法は次のとおりです。

 public static void CopyStream(Stream input, Stream output)
 {
    // Insert null checking here for production
    byte[] buffer = new byte[8192];
    int bytesRead;
    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
    {
        output.Write(buffer, 0, bytesRead);
    }
}
.

私が興味があるのは次のとおりです.bufferはスタック上または上に割り当てられます。 ヒープ?確かに、このメソッドを安全にすることができ、fixedキーワードを追加することができます。 変数宣言ですが、私はそうする必要がないIFNをやりたくありません。

役に立ちましたか?

解決

The buffer variable will be allocated on the stack, the 8192 byte memory the buffer variable holds the location of will be on the heap.

why are you talking about fixed? Are you trying to speed things up? It almost certainly won't...

To quote Eric Lippert:

"But in the vast majority of programs out there, local variable allocations and deallocations are not going to be the performance bottleneck. "

Ref.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top