内存利用率:WPF 与 Windows 窗体

发布于 2024-10-06 00:57:48 字数 219 浏览 0 评论 0原文

一个功能为零的简单示例应用程序显示了内存利用率的惊人差异。

数字采用私有字节并使用 .NET 4.0。

  • WPF - 56MB
  • Windows 窗体 - 13MB

众所周知,框架不擅长做任何事情,但我仍然对这种差异感到惊讶。作为使用 WPF 的成本,我是否可以预期使用 WPF 构建的应用程序将多消耗 30-40MB 的私有字节?

A simple sample application that has zero functionality shows a surprising difference in memory utilization.

Numbers are in private bytes and using .NET 4.0.

  • WPF - 56MB
  • Windows Forms - 13MB

Frameworks are notoriously bad at doing nothing, but I'm still surprised by this difference. Can I expect that an application built with WPF will consume 30-40MB more in private bytes as a cost of using WPF?

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

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

发布评论

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

评论(3

别理我 2024-10-13 00:57:48

从这个数据来看,没有。您可以推断出,一个不执行任何操作的应用程序将在 WPF 中多消耗 43MB 的空间。

我的观点是,随着应用程序使用更多功能,差异可能会增加、减少或保持不变。没办法知道。

From this data, no. What you can deduce is that an application that does exactly nothing will consume 43MB more in WPF.

My point being that as more features get used by the application, the difference might increase, decrease, or stay constant. No way to know.

白云悠悠 2024-10-13 00:57:48

我建议您尝试在 WPF 中创建一个包含 10,000 个控件的 UI,并在 WinForms 中创建一个类似的 UI,然后检查内存使用情况。以编程方式执行此操作非常简单 - 例如,只需创建一个 Form 并将 10,000 个 TextBox 对象添加到其 Controls 集合中。 (剧透警告:在 WinForms 中,您需要使用小于 10,000 的数字。)这也不会为您提供特别准确的比较点,但它比不执行任何操作的应用程序更准确,而且它会教您有关无窗口控件的宝贵课程。

I recommend that you try creating a UI with 10,000 controls in it in WPF, and a similar UI in WinForms, and then check to see what the memory usage is. It's fairly simple to do this programmatically - just create a Form and add 10,000 TextBox objects to its Controls collection, for instance. (Spoiler alert: you'll need to use a number that's smaller than 10,000 with WinForms.) This won't give you an especially accurate point of comparison either, but it's a more accurate one than an app that does nothing, and it will teach you a valuable lesson about windowless controls.

丶视觉 2024-10-13 00:57:48

WPF(及其基本控件)提供了更多的功能,因此增加的开销是可以预料的。

WPF 的优点是它比 WinForms 更“开发人员时间效率”(创建丰富的 UI),而不是“内存效率”或“CPU 效率”。

尽管由于 WPF 完全由 GPU 加速,所以在某些情况下性能提升是可以预期的。但这些并不是您在任务管理器中可以看到的性能提升,这些性能提升以动画平滑度和用户响应能力提高的形式变得显而易见。

WPF (and its basic controls) offer much more features, so increased overhead is to be expected.

The advantage of WPF is that it is more "developer time efficient" (to create rich UIs) than WinForms, not more "memory efficient" or "CPU efficient".

Though since WPF is fully GPU-accelerated, performance gains are to be expected in some cases. But these are not the performance gains you can see in task manager, these become apparent in form of increased animation smoothness and user responsiveness.

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