Click here to Skip to main content
15,888,217 members
Articles / General Programming / File
Alternative
Tip/Trick

BufferedFileReader & BufferedFileWriter: extending BinaryReader and BinaryWriter using BufferedStream

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
16 Mar 2011CPOL 10.8K   2   4
Unless I'm wrong, the FileStream is buffered, no?
Unless I'm wrong, the FileStream is buffered, no?

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Free SAS
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralYes. The ReadStruct<T> function may help me for some situati... Pin
Đỗ Hồng Ngọc17-Mar-11 2:09
professionalĐỗ Hồng Ngọc17-Mar-11 2:09 
GeneralHi Olivier, I don't think your class is faster. For FileStr... Pin
Đỗ Hồng Ngọc15-Mar-11 5:18
professionalĐỗ Hồng Ngọc15-Mar-11 5:18 
GeneralRe: All right, so just forget about my buffered classes :) You c... Pin
Olivier Levrey16-Mar-11 23:08
Olivier Levrey16-Mar-11 23:08 
GeneralYou are not wrong, <CODE>FileStream</CODE> is buffered. The ... Pin
Olivier Levrey14-Mar-11 23:52
Olivier Levrey14-Mar-11 23:52 
You are not wrong, FileStream is buffered. The reason why I didn't mention it is just because I didn't know it!! I searched MSDN for handling files and streams, found the examples using StreamReader, BinaryReader, TextWriter, and so on but I hadn't found that one... Anyway, I did (quickly) a few tests to compare FileStream.Write and my BufferedFileWriter.Write function (I wrote the exact same data several times and in different orders) and it appears that my class is about 10% faster. Not much. Probably because the size of the internal buffer is different. Thank you for your comment. Even though they are a little bit faster, I think the use of BufferedFileWriter and BufferedFileReader classes makes less sense now!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.