Click here to Skip to main content
15,117,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am reading about stream and buffer in C Language.
I got that if stream is line buffered then the accumulated characters of buffer get transferred in the from of block whenever the newline character encounter.
and if stream is unbuffered then character are intended to appear from the source or appear at the destination as soon as possible without getting store in buffer.

but if stream is fully buffered then the accumulated characters of buffer get transfered in the form of block whenever the buffer get totally filled.
Now I am unable to understand that in which condition the buffer get totally filled.From where the buffer decides it's size?

What I have tried:

I have learnt about line buffered and got it clearly but there is problem with fully buffered.
Updated 15-Jun-21 20:05pm

1 solution

From the source:
When a stream is fully buffered, characters are intended to be transmitted to or from the host environment as a block when a buffer is filled.

Basically, with a fully buffered stream the source sends nothing until it's output buffer is completely full, or it reaches the end of data it wants to send.
So the destination gets no data until a buffer full is available (or the end of the source is reached).

Think of it as a shop selling loose peanuts: the assistant pours 500g into a bag and hands it over to the customer. Then they pour another 500g into another bag, and pass that over as well. Then finally, he pours 250g into a third bag, and the customer has his 1.25Kg of nuts, and can pay and go.
The bag can't take more than 500g, so that's what gets "delivered" at any one time.
surajgirioffl 16-Jun-21 2:19am
@OriginalGriff: How output buffer gets completly full? actually I want to know that how it know that it reached at the end of data?

In line buffered when '\n' encounter then it understand it is end point and sends the data but there is no such condition in fully buffererd, here condition is that when the buffer get full then only it can send the data. but I want to know that when the buffer gets full? what are the conditions on which it knows that I am full, now I will send the data that I have stored.

I think you understand my problem.
OriginalGriff 16-Jun-21 3:51am
Go back to the "shop" analogy.
You are the assistant, and I want 1.25Kg of nuts. Your bags only hold 500g.
How do you know when to stop pouring nuts into a bag?
Richard MacCutchan 16-Jun-21 5:53am
When the manager shouts, "you're spilling the nuts you fool". :)
OriginalGriff 16-Jun-21 6:54am

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900