开发者

Reasons for using C++/CLI instead of c#?

I wrote a managed C++ application a few years ago. It was just a personal project and I chose managed c++ just because I found it interesting. I remember it felt like it just took a lot more time than doing c# and there wasn'开发者_JAVA百科t anything to gain from it in my case at least.

When is C++/CLI a good choice in reality? What is it's benefits?


The only reason for using C++/CLI is so you can use a native library in a managed application. Even Microsoft says it shouldn't be used on its own:

The second major consideration for using C++/CLI is to remember that this is only intended to be a bridge between the managed and native worlds and not intended to be a technology you use to write the bulk of your application. It is certainly possible to do so, but you'll find that developer productivity is much lower than in a pure C++ or pure C#/Visual Basic environment and that your application runs much slower to boot. So when you use C++/CLI, compile only the files you need with the /clr switch, and use a combination of pure managed or pure native assemblies to build the core functionality of your application.

http://msdn.microsoft.com/en-us/magazine/dd315414.aspx#id0070020


For me, it's far less difficult to write managed code in C#, but sometimes the performance that C++ offers makes it a better choice. I write the performance-critical code in c++, and the rest in C#. The only reason for C++/CLI is so that the native code and managed code can be used together.

Herb Sutter's design rational:

C++/CLI’s mission is to provide direct access for C++ programmers to use existing CLI libraries and create new ones, with little or no performance overhead, with the minimum amount of extra notation, and with full ISO C++ compatibility.

http://www.gotw.ca/publications/C++CLIRationale.pdf

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜