/
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. 20.08.2020 at 08:59 pm / A Case for Legalese (Or Not)
  2. 02.01.2018 at 12:00 am / Genuinely Technical Modesty
  3. 08.02.2016 at 12:00 am / Eye to Eye (Jonathan Young's Version)
  4. 08.06.2015 at 12:00 am / Knowledge Trees
  5. 17.12.2014 at 12:00 am / 午・午年
  6. 07.07.2014 at 12:00 am / If I Cannot Strengthen Our Bench
  7. 11.11.2013 at 12:00 am / 下戸 - Lower House
  8. 14.08.2010 at 12:00 am / Basic Kanji Learning Principles
© Wan Zafran. See disclaimer.