DoubleBuffer''''ing is commonly used in graphics programming to produce flicker-free animation. While one buffer of pixel data is visible, the program builds the next frame of animation in an off-screen buffer. The on-screen and off-screen buffers are then flipped, so that the new frame is displayed. The buffer that was on screen is now used to build the next frame. However, DoubleBuffer''''ing is useful in any system in which one process generates data to be consumed by another concurrent process. '''Using a DoubleBuffer can fail when data is generated during lengthy buffer flips.''' If the flip takes long enough, there can be a time when there is no valid buffer to write to. Therefore: '''Use three buffers to pass data between concurrent processes.''' Very similar to a DoubleBuffer, a TripleBuffer uses three buffers to manage the data pipeline. With TripleBuffer''''ing, there will always be a buffer to write to while a transition is in progress between the other two. In graphics programming, the buffer system is sometimes generalized into a FlipChain. For instance, you require four buffers to correctly manage the rendering pipeline if you must use timed transitions between buffers like a wipe or an alpha transition. ''A FlipChain is essentially a CircularBuffer of buffers.'' ---- I wrote a TripleBuffer like the above to process magnetic tapes in the middle 1960s. Input into buffer0, process buffer1, output from buffer2, cycle the three pointers around and repeat... Another use for multiple buffers is to allow a simple read-ahead or look-ahead mechanism to implement a kind of TimeMachine that can see the future. ---- TripleBuffer also applies to graphic displays with a complex computationally expensive background (a raster or 3d rendered terrain) with lighter-weight more frequently updated graphics on top. ---- In Quake I, triple buffering was used to allow the rendering engine to render at 100% CPU regardless of CPU speed. One buffer would be the buffer currently being displayed. A second buffer would be a buffer that had already been rendered and was ready to display at any time. A third buffer would be the buffer currently in the process of being rendered. If the CPU was very fast, the third buffer might be completed before the second buffer was ever used, so the second and third buffers would simply be swapped and the CPU would go ahead and render another frame. Whenever it was time for the monitor to do a vertical refresh, the program would check whether a second buffer was available. If so, the first and second buffers would be swapped. So, triple-buffering can be used to drop or duplicate frames when converting from one video refresh rate to another. ---- Also see GraphicsPatterns, DoubleBuffer, CircularBuffer. CategoryGraphicsPattern CategoryPattern