Archive for 15 febrero 2009

Double Buffering, It Works

Double buffering is something that has always bugged me, like databases and web programming, not because it’s complicated (at least in a high level language like C#) but because I didn’t understand it (the same happened with those other two things, until one year ago, and now I like them a lot).
It all started some days ago when I had an aha moment and got back to programming, this time a tag cloud control for the .NET framework. The problem was that when I resized the control, and in doing so the tag cloud, some horrible, terrible and annoying flickering of the labels inside of it took place.
I put off that part and keep working on other thing, until today when I decided something had to be done, so I straightened in my chair, took a deep breath, pulled up my sleeves and wrote in the control’s constructor:

this.DoubleBuffered = true;

And that was it, sayonara to the flickering. I must admit I just tested it with a small amount of data, but with that same amount of data and without double buffering, you had to look away while resizing the window because the flickering might leave you blind.

So what’s all this double buffering thing about? instead of outputting each control to the monitor everytime it has to be redrawn, the things that need to be refreshed are stored in the central memory for a little while and then batch-displayed.
Obviously, this explanation is oversimplified, so you know who to ask if you want to know more.
Wikipedia, we love you! :)