Why is DoubleBuffered disabled by default?

后端 未结 4 1953
后悔当初
后悔当初 2020-12-15 04:24

After creating a new form, I usually perform this ritual:

  1. Change the name into something meaningful;
  2. Type a Caption;
  3. Change the
4条回答
  •  爱一瞬间的悲伤
    2020-12-15 04:58

    As you probably know, a double buffer normally involves creating an off-screen memory buffer the same size as the visual component. Writing/drawing is performed on this buffer and when complete, the entire buffer is "swapped" so that it is now painted on the visual component.

    (Note: "swapping" may consist of simply changing the address a pointer points to, or may actually involve copying a chunk of memory such as using BitBlt, memcpy etc)

    Therefore a reasonable amount of memory allocated to support this process for each component it is enabled for. If your application has many windows or and/or components there would be a not insignificant amount of memory allocated. If you do not require smooth visual updates/scrolling, why waste this memory?

    Of course there is also an argument that today most computers have plenty of memory to spare, so why worry. However I still don't see this as a reason to default to enabling Double Buffering if you don't need it.

    If manually setting DoubleBuffered to true is a pain for you, you could always create your own custom control/component that inherits from the built-in control, and sets DoubleBuffered (and other properties) to your required defaults.

提交回复
热议问题