为什么 DoubleBuffered 默认被禁用?

发布于 2024-08-04 15:04:20 字数 377 浏览 4 评论 0原文

在创造出一种新形式后,我通常会进行这样的仪式:

  1. 将名称更改为有意义的东西;
  2. 输入标题
  3. 更改位置属性(DefaultPosOnly 几乎不是用户所期望的);
  4. 将 ShowHint 设置为 true ;
  5. DoubleBuffered设置为true

我一直想知道为什么默认值是“False”。对我来说,它看起来技术含量低且蹩脚,在我的新机器上我没有注意到性能有任何差异。

双缓冲在旧机器、VNC、远程桌面或虚拟机上可能有问题吗?

你把它打开还是关闭?有什么建议吗?

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

  1. Change the name into something meaningful;
  2. Type a Caption;
  3. Change the position property (DefaultPosOnly is hardly ever what users expect);
  4. Set ShowHint to true;
  5. Set DoubleBuffered to true;

I've been wondering for a while why the default value is 'False'. To me it just looks low-tech and crappy, and on my new machine I don't notice any difference in performance.

Is doublebuffering problematic on older machines, VNC, Remote Desktop or in Virtual Machines maybe?

Do you leave it on or off? Any recommendations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

晨与橙与城 2024-08-11 15:04:20

您可能知道,双缓冲区通常涉及创建与可视组件大小相同的离屏内存缓冲区。在此缓冲区上执行写入/绘图,完成后,整个缓冲区将被“交换”,以便现在将其绘制在可视组件上。

(注意:“交换”可能只是简单地更改指针指向的地址,或者实际上可能涉及复制一块内存,例如使用 BitBlt、memcpy 等)

因此,为每个组件分配合理的内存量以支持此过程已启用。如果您的应用程序有许多窗口或和/或组件,则分配的内存量将不少。如果您不需要流畅的视觉更新/滚动,为什么要浪费这些内存呢?

当然,还有一种说法是,如今大多数计算机都有足够的空闲内存,所以何必担心呢。但是,如果您不需要的话,我仍然不认为这是默认启用双缓冲的原因。

如果手动将 DoubleBuffered 设置为 true 对您来说很痛苦,您始终可以创建自己的自定义控件/组件,该控件/组件继承自内置控件,并将 DoubleBuffered (和其他属性)设置为您所需的默认值。

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.

仅此而已 2024-08-11 15:04:20

在执行某种远程桌面时应避免双缓冲,因为必须通过网络发送控件/表单的整个位图才能执行 BitBlt。请参阅此博文...

Double buffering is to be avoided when doing Remote Desktop of some sort, since the whole bitmap of the control/form has to be sent over the network to do the BitBlt. see this blog post...

雪化雨蝶 2024-08-11 15:04:20

在进行桌面合成的现代操作系统上,双缓冲实际上可能会降低性能。无论如何,渲染都是在离屏位图上执行的,因此使用双缓冲会导致额外的复制,而在这些系统上根本没有任何好处。因此,除非 VCL 足够聪明,能够在这种情况下忽略双缓冲(不知道是否会忽略,需要检查),否则实际上最好不要无条件设置它。

编辑:

我检查过,在 Delphi 2007 和 Delphi 2009 中,当 DwmCompositionEnabled 返回 时,TWinControl.WMPaint 方法不使用双缓冲确实如此。好的。

On a modern OS which does desktop compositing double buffering may actually decrease performance. Rendering is performed into an off-screen bitmap anyway, so using double buffering leads to an extra copying for no benefit at all on those systems. So unless the VCL is smart enough to ignore the double buffering in that case (don't know whether it does, would need to check) it may actually be better to not set it unconditionally.

Edit:

I checked, and in both Delphi 2007 and Delphi 2009 the TWinControl.WMPaint method does not use double buffering when DwmCompositionEnabled returns True. Nice.

绝不放开 2024-08-11 15:04:20

您还可以创建一个设计时专家,自动为您创建的每个表单/控件设置此值,而不是为每个现有控件派生新控件,这将涉及更多工作。
请参阅 GExperts.org 上的源代码以了解如何实现这一目标。

You could also create a design-time expert that automatically sets this value for every form/control you create, instead of deriving new controls for every existing one which would involve much more work.
See source code at GExperts.org to get an idea how to achieve this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文