문제

소켓 스트림에서 디스크로 바이트를 복사하는 다음 방법이 있습니다.

 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 키워드를 추가 할 수 있습니다. 변수 선언이지만, 나는 그렇게하지 않아야합니다.

도움이 되었습니까?

해결책

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