C ++ CLI。本地部分是用纯C ++编写的,但在CLI中编译的速度和纯本地C ++一样快? [英] C++CLI. Are native parts written in pure C++ but compiled in CLI as fast as pure native C++?

查看:178
本文介绍了C ++ CLI。本地部分是用纯C ++编写的,但在CLI中编译的速度和纯本地C ++一样快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将音频计算委派给C ++图层,但是通过WPF GUI处理和编辑音频内容。

I want to delegate audio computing to a C++ layer, but handle and edit audio content through a WPF GUI.

我简单看了一下C ++ / CLI ,我想知道:

I have had a brief look at C++/CLI, and I wanted to know:


  • 应该使用C ++ / CLI作为C#GUI和C ++音频管理之间的中间层

  • 或者我应该把我的代码放在C ++ / CLI中,并且期望它以相同的方式编译,因此效率很高。

编辑:因为火焰战争可能开始。
此链接指向基准游戏,清楚地说明C / C ++作为速度获胜者。 我问:我应该把我的C ++写在C ++ Dll,或者在C ++ CLI程序集。

as the flaming war may begin. This is a link that goes to the benchmarks game, that clearly states the C/C++ as a speed winners. I am asking: Should I write my C++ in a C++ Dll, or in a C++CLI assembly.

推荐答案

在C ++ / CLI中,托管类型(例如 ref class )及其成员编译为MSIL。这意味着不使用SIMD,并且更少的优化(至少在当前版本的.NET中,并且微软给出的理由不会很快改变,虽然他们可以改变他们对权衡的评估)。

In C++/CLI, managed types (ref class for example) and their members are compiled to MSIL. This means no use of SIMD, and much less optimization (at least in the current version of .NET, and the reasons given by Microsoft aren't changing any time soon, although they could change their assessment of the tradeoffs).

另一方面,本机类型可以编译为MSIL或本地机器代码。虽然Visual C ++没有最好的C ++优化器在世界上,这是非常非常好。所以我的建议是编译为本地代码。 Visual C ++在托管和本地代码之间调用时将使用C ++互操作,这是非常有效的(它是相同的 internalcall 技术用于所有.NET的内置函数,如string

Native types, on the other hand, can be compiled either to MSIL or to native machine code. Although Visual C++ doesn't have the best C++ optimizer in the world, it's very very good. So my recommendation would be to compile to native code. Visual C++ will use C++ interop when calling in between managed and native code, which is very efficient (it's the same internalcall technology used for all .NET's built-in functions such as string concatenation).

为了做到这一点,你可以把你的时间关键代码放在一个单独的目标文件(不是单独的DLL !,让链接器组合管理和非托管编译成一个混合模式程序集)编译时没有 / clr ,或用 #pragma托管(push,off) ... #pragma managed(pop)。任何一种方式都将获得最大的优化,并允许您使用SIMD内在函数来实现非常快速的代码。

To make this happen, you can either put your time-critical code in a separate object file (not separate DLL!, let the linker combine managed and unmanaged code together into a "mixed-mode" assembly) compiled without /clr, or bracket it with #pragma managed(push, off) ... #pragma managed(pop). Either way will get you maximum optimizations and allow you to use SIMD intrinsics for very speedy code.

这篇关于C ++ CLI。本地部分是用纯C ++编写的,但在CLI中编译的速度和纯本地C ++一样快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆