Cuttings: Triple Buffered Painters Triple Buffered Painters | Cuttings

Things of interest.

August 25, 2020

Triple Buffered Painters

Lovely ELI5 metaphor on the buffering/rendering process.

The buffers in question are memory areas where you can store an image. When the computer creates an image, it writes it in the buffer. The display system will read from the buffer and display it on the screen several dozen times per second.

Let’s say Alice is in charge of producing the images and Billy is in charge of displaying the images. The buffer is a canvas, Alice is a painter that paints things on the canvas and Billy is taking pictures of the canvas at regular intervals and shows them to you, the user.

If there’s only one buffer (one canvas) it may happen that Alice is not finished with painting when Billy takes the picture. So Billy will take a picture of a partially painted canvas and show it to you. This will result in flicker: some of the images you’re getting are only partially done or partially modified.

To solve this, Alice and Billy will use double-buffering: there are now two canvases, one for Alice and one for Billy. There’s also a third person, Charlotte, in charge of swapping the canvases when Alice is finished. So now, Billy is always taking a picture of a complete painting. When Alice finishes her current painting, Charlotte swaps the canvases so that Billy can take a picture of the new painting, and Alice can start the next painting on the other canvas.

This works well (no more flicker) but it isn’t optimized for speed: Charlotte is synchronized with Billy: she won’t switch the canvases if Billy is in the process of taking a picture, she must wait for the moment Billy is showing you the picture. And then the switch itself takes some time. This means that Alice, once she’s done with a painting, must wait for Charlotte to complete the switch before she can start the next painting. In the meantime Alice isn’t doing anything, which isn’t optimal.

A solution to optimize speed is triple buffering: our friends are now using, you guessed it, three canvases. One for Billy and two for Alice. Now, each time Alice finishes a picture, she can already start the next picture on her other canvas, she doesn’t need to wait for Charlotte to switch the previous canvas with Billy. So now Billy and Charlotte are still synchronized, but Alice doesn’t need to care about them, she’ll always have a canvas to paint on and she doesn’t waste time waiting anymore.

- Source: Reddit/ELI5


- Areas: Code / Music / Gaming
- Lang: Japanese / French / English
- Hume: Law / Work / Learning / People
- All: Tags / Posts
© 1997 - 2020 / Info