Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use .NET BufferedStream class?

The MSDN site states:

A buffer is a block of bytes in memory used to cache data, thereby reducing the number of calls to the operating system. Buffers improve read and write performance. A buffer can be used for either reading or writing, but never both simultaneously. The Read and Write methods of BufferedStream automatically maintain the buffer.

Should I use this class in every possible occasion?

like image 970
Jader Dias Avatar asked Jan 29 '09 16:01

Jader Dias


1 Answers

According to Brad Abrams, almost never: link

No, there is zero benefit from wrapping a BufferedStream around a FileStream. We copied BufferedStream’s buffering logic into FileStream about 4 years ago to encourage better default performance... In fact, I don’t think there are any Streams in the .NET Framework that require it, but it might be needed by custom Stream implementations if they do not do buffering by default.

like image 145
dewald Avatar answered Oct 01 '22 11:10

dewald