I have the following method to copy bytes from a socket stream to disk:
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);
}
}
What I am curious about is: will buffer
be allocated on the stack or on the
heap? To be sure, I could make this method unsafe, and add the fixed
keyword to
the variable declaration, but I don't want to do that ifn I don't have to.