Buffered Streams C# Help

For performance reasons, when you read or write to or from a file, the output is buffered, This means that if your program asks for the next 2 bytes of a file stream, and the stream passes the request on to Windows, then Windows will not go through the trouble of connecting to the file system and then’ locating and reading the file off the disk, just to get 2 bytes.

Instead, Windows will retrieve a large block, of the file at one time and store this block in an area of memory known as a buffer, Subsequent requests for data from the stream are satisfied from the buffer until the buffer runs out, at which point, Windows grabs another block of data from the file, Writing to files works in the same way, For files, this is done automatically by the operating system, but you might have to write a stream class to read from some other device that is not buffered, If so, you can derive your class from BufferedStrearm which implements a buffer itself.

(Note, however, that BufferedStrearn is not designed for the situation in which an application frequently alternates between reading and writing data.)

Posted on October 28, 2015 in Manipulating Files and the Registry

Share the Story

Back to Top