Connecting Tech Pros Worldwide Help | Site Map

what is the difference between unbuffered and buffered stream??

Newbie
 
Join Date: Aug 2009
Location: Pakistan
Posts: 25
#1: Aug 11 '09
what is the difference between unbuffered and buffered stream??
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,387
#2: Aug 11 '09

re: what is the difference between unbuffered and buffered stream??


buffered streams store data in a buffer before and during access. unbuffered streams do not.
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 828
#3: Aug 11 '09

re: what is the difference between unbuffered and buffered stream??


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.
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,387
#4: Aug 11 '09

re: what is the difference between unbuffered and buffered stream??


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.
Newbie
 
Join Date: Aug 2009
Location: Pakistan
Posts: 25
#5: Aug 12 '09

re: what is the difference between unbuffered and buffered stream??


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.
Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 828
#6: Aug 12 '09

re: what is the difference between unbuffered and buffered stream??


Quote:

Originally Posted by zeeshan708 View Post

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.

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?
Newbie
 
Join Date: Aug 2009
Location: Pakistan
Posts: 25
#7: Aug 12 '09

re: what is the difference between unbuffered and buffered stream??


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
Reply