views:

121

answers:

3

I've a question about buffer usage with StreamReader. Here: http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx you can see:

"When reading from a Stream, it is more efficient to use a buffer that is the same size as the internal buffer of the stream.".

According to this weblog , the internal buffer size of a StreamReader is 2k, so I can efficiently read a file of some kbs using the Read() avoiding the Read(Char[], Int32, Int32).

Moreover, even if a file is big I can construct the StreamReader passing a size for the buffer

So what's the need of an external buffer?

A: 

Have you tried reading a file byte by byte using Read() compared to having an external buffer? Its an order of magnitude slower...

ck
A: 

I think this question was already asked somehow differently on stackoverflow: http://stackoverflow.com/questions/129305/how-to-write-the-content-of-one-stream-into-another-stream-in-net

"When using the Read method, it is more efficient to use a buffer that is the same size as the internal buffer of the stream, where the internal buffer is set to your desired block size, and to always read less than the block size. If the size of the internal buffer was unspecified when the stream was constructed, its default size is 4 kilobytes (4096 bytes)."

garzanti
+1  A: 
František Žiačik