Sams Teach Yourself C++ in 21 Days

(singke) #1
When the water (data) reaches the top, the valve opens and all the water flows out in a
rush. Figure 17.3 illustrates this.

596 Day 17


FIGURE17.3
Emptying the buffer.

After the buffer is empty, the bottom valve closes, the top valve opens, and more water
flows into the buffer tank. Figure 17.4 illustrates this.

FIGURE17.4
Refilling the buffer.

Every once in a while, you need to get the water out of the tank even before it is full.
This is called “flushing the buffer.” Figure 17.5 illustrates this idea.
You should be aware that one of the risks of using buffering is the possibility that the
program will crash while data is still in the buffers. If this occurs, you might lose that
data.
Free download pdf