423,680 Members | 2,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,680 IT Pros & Developers. It's quick & easy.

what is the difference between unbuffered and buffered stream??

P: 25
what is the difference between unbuffered and buffered stream??
Aug 11 '09 #1
Share this Question
Share on Google+
6 Replies


RedSon
Expert 5K+
P: 5,000
buffered streams store data in a buffer before and during access. unbuffered streams do not.
Aug 11 '09 #2

Expert 100+
P: 2,384
When you read from a buffered stream you actually read from an input buffer created and managed by the library. Characters move from the input stream to the input buffer by magic.

When you write to a buffered stream you actually write to an output buffer created and managed by the library. Characters move from the output buffer to the output stream by magic.

By magic, I mean some mechanism that is at least partially implementation-specific.

Buffering a stream can improve the overall efficiency of the application program; but at the cost of making it less certain when the real I/O operation takes place.
Aug 11 '09 #3

RedSon
Expert 5K+
P: 5,000
Also, we should mention here that when writing or reading from an unbuffered stream you have a chance that no one will be there to take the data you have written or that there will be data there for you to read.
Aug 11 '09 #4

P: 25
thank u donbock and redson but the point is still not clear,,how can we choose between a buffered and unbuffered stream??and what is the main advantage of a buffered stream??? we say that cerr uses unbuffered stream and cout use buffered but i am unable to get the logic behind it.
reply shall be appreciated.
thanx.
Aug 12 '09 #5

Expert 100+
P: 2,384
@zeeshan708
Are you asking about the standard streams (cin, cout, cerr, clog); or are you concerned with some other stream?

Are you asking for the mechanics of how to coerce a stream to be buffered/unbuffered; or are you asking the more abstract question of why do buffered/unbuffered I/O exist?

Why don't you start off by explaining to us what you understand about buffered vs unbuffered I/O?
Aug 12 '09 #6

P: 25
I am asking about the standard streams,,,,what i think is that may be in buffered stream the data first comes into some registers and then as the registers get full the data is sent out and in case of unbuffered data goes directly,,but thats just a ruff idea in my mind,,i want a clear answer, thanx alot
Aug 12 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.