/
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. 09.07.2023 at 11:38 am / Non-Dissonant Speed Keybindings
  2. 31.07.2022 at 10:08 pm / Hades And (Non-Ending) Desk Jobs
  3. 20.06.2022 at 01:56 pm / Cultists of Science
  4. 11.06.2022 at 09:09 pm / 大蛇に嫁いだ娘 - The Girl Married to the Giant Serpent
  5. 30.04.2022 at 10:36 am / Masters of A Fraction of A Dot
  6. 27.08.2020 at 09:33 pm / Write Like You Play Tetris
  7. 16.12.2017 at 12:00 am / When Defying Simplicity
  8. 03.01.2017 at 12:00 am / Debugging: Twice As Hard As Writing Code
  9. 16.01.2015 at 12:00 am / Ih Ah! (Devin Townsend)
  10. 16.08.2010 at 12:00 am / You Have Reason
© Wan Zafran. See disclaimer.