在 Windows8 中编写 C#/XAML 与 C++/XAML WinRT 应用程序的优缺点是什么?优缺点、应用程序、XAML、WinRT

2023-09-06 06:00:24 作者:都TM的是贱人

我想了解将 WPF/Silverlight 组件移植到 Windows 8 的路线.对于一些上下文,该组件是 实时 WPF 图表,它使用 WPF/XAML 和位图渲染的混合来实现高性能.

I'd like to go down the route of porting a WPF/Silverlight component to Windows 8. For a bit of context, the component is a real-time WPF Chart, which uses a mixture of WPF/XAML and bitmap rendering to achieve high performance.

我希望该组件与 Metro 兼容,例如用于 Metro 模式和桌面模式.我读了很多关于创建 C++/WinRT Windows 8 中的应用程序以及 C#/XAML 应用程序,但是这两个框架之间有什么区别?

I'd like the component to be Metro compatible, e.g. used in metro mode as well as desktop mode. I read a lot about creating C++/WinRT applications in Windows 8 as well as C#/XAML applications, but what are the differences between the two frameworks?

如果您选择 C#/XAML 而不是 C++/XAML,是否有限制?还要考虑从 .NET4.0 中的 C#/Xaml 移植到 Windows8 会容易得多,如果我可以坚持使用 C#/XAML,但是我能否使用这种方法创建功能齐全的 Metro 组件?

Are there limitations if you choose C#/XAML over C++/XAML? Also consider the porting from C#/Xaml in .NET4.0 to Windows8 would be far easier if I could stick to C#/XAML, however will I be able to create a fully featured Metro component using this method?

感谢您的意见/建议.

如果您投票关闭此线程,请发表评论原因.这是一个有效的问题,有 +6 票,四个答案和一个最爱.把它留给我似乎是合理的!

If you're voting to close this thread, please post a comment why. Its a valid question, has +6 votes, four answers and one favourite. Seems reasonable to keep it to me!

推荐答案

我认为差异是一种设计选择,而不是个人对语言的偏好.偏好与 VB 与 C# 更相关.通常,在您选择 C++ 或 .NET 的任何应用程序中,您会得到相同的差异.

I see the difference as a design choice, than a personal preference of language. Preference would be more related to VB vs C#. And generally it's the same differences you get in any application where you choose C++ or .NET.

C++ 将为您提供更快的启动时间.IIRC,.NET 4.5 具有自动 NGENing 功能(不确定它与 Metro 应用程序的关系如何),因此这可能有助于缓解 .NET 应用程序的典型缓慢启动时间.

C++ will give you faster startup times. IIRC, .NET 4.5 has auto NGENing abilities (not sure how it related to metro apps), so this may help mitigate typical slow startup times of .NET applications.

C++ 不会使用垃圾收集器,因此可以降低一般内存使用量.这在平板电脑等资源受限的设备上变得越来越重要.IIRC,.NET 4.5 对 GC 暂停有更多的缓解措施(这可能导致 UI 混乱),它们仍然是托管代码的现实.

C++ will give you lower general memory usage as it does not use a garbage collector. This becomes increasingly more important on resource constrained devices such as tablets. IIRC, .NET 4.5 has more mitigations into GC pauses (which can cause the UI to studder), they are still a reality with managed code.

由于 .NET 和 C++ 使用相同的 WinRT 框架,因此与 XAML/WinRT 平台交互可能不会有太大差异(通过 C++ 与 WinRT 对象交互在技术上更快,但影响非常小),但当然,使用 C++ 的用户代码通常比使用 .NET 更快.

Since .NET and C++ use the same WinRT framework, there probably won't be too much difference in interacting with the XAML/WinRT platform (technically faster interacting with WinRT objects via C++ but the hit is really small), but of course your user code will generally be faster with C++ than .NET.

C++ 通常更难逆向工程,即使与模糊的 .NET 代码相比也是如此.尽管狡猾的小偷无论如何都可以窃取您的 IP.

C++ is generally more difficult to reverse engineer, even when compared with obfuscated .NET code. Though sly thieves can steal your IP regardless.

由于 .NET 最初是为了方便开发人员和开发人员的工作效率而创建的,因此您在构建应用程序时将拥有更多方便的选择(例如,基于反射的工具,例如 DI/IoC).

Since .NET was created first for the convenience of the developer and developer productivity, you will have more convenience options in architecting your applications (eg, reflection based tools such as DI/IoC).

通过 .NET 迭代应用程序代码可能更容易,因为 .NET 的编译速度比 C++ 快,但正确创建的 C++ 项目可以大大缓解这种情况.

Iterating application code may be easier via .NET as .NET compiles quicker than C++, but correctly created C++ projects this can be mitigated substantially.

纯 .NET 项目可以支持任何 CPU",这意味着您的应用程序可以在所有受支持的 WinRT 平台上运行.您只需重新编译 C++ 项目即可支持 ARM、x86/64.如果您的 .NET 应用程序依赖于自定义 C++ 组件,则必须针对每个架构进行编译.

Pure .NET projects can support "Any CPU", which means your application can run on all supported WinRT platforms. C++ projects you will simply have to recompile to support ARM, x86/64. If you .NET application depends on a custom C++ component, you will have to compile for each architecture.

因为 WinRT 是从一开始就支持多种语言的,所以我对不熟悉 C++ 的开发人员的建议是坚持使用 .NET,但探索受益于 C++ 的领域.Microsoft 在/CX 预测方面做得很好,大多数 C# 开发人员应该能够找到自己的方法.我对 C++ 开发人员的建议是坚持使用 C++ 并获得 C++ 的所有好处.

Because WinRT was created from the ground up to support many languages, my suggestion to devs that arent comfortable with C++ is to stick with .NET but explore areas that benefit from C++. Microsoft has done a great job with the /CX projections and most C# devs should be able to find their way around. My suggestion to C++ devs is to stick with C++ and get all the benefits of C++.