/
25.08.2020 at 08:42 am
Cuttings

Triple Buffered Painters

Useful metaphor for buffering/rendering/switching canvases.

... 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.

- Reddit

Filed under:
#
#
Words: 420 words approx.
Time to read: 1.68 mins (at 250 wpm)
Keywords:
, , , , , , , , ,

Other suggested posts

  1. 01.04.2023 at 11:27 am / Search Notes Fast: With Taskwarrior, jq & ripgrep
  2. 17.10.2022 at 12:31 pm / AI Art Is Real Art
  3. 21.07.2021 at 07:46 am / Basis for Base64
  4. 03.07.2021 at 10:31 am / Learning Forever
  5. 14.01.2020 at 01:24 pm / Third Time's A Charm
  6. 22.08.2018 at 02:13 pm / Heinrich Schliemann's Learning Method
  7. 12.03.2016 at 12:00 am / Transcript of Tifa Funk - Interlude Solo (Tifa's Theme by Tetrimino)
  8. 26.12.2013 at 12:00 am / Teal Stares
  9. 28.11.2013 at 12:00 am / ケチ - Scroogean Niggardliness
  10. 21.07.2012 at 12:00 am / Hunted By GLaDoS
© Wan Zafran. See disclaimer.