混合模式C ++ / CLI性能注意事项 - 最佳做法 [英] Mixed mode C++/CLI performance considerations - best practices

查看:134
本文介绍了混合模式C ++ / CLI性能注意事项 - 最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++ / CLI库调用许多本地C ++方法。我读了很多线程,表明你不应该混合托管和非托管代码。我找不到任何说,如何避免这些开关,为什么会导致性能问题。有人可以分享最佳做法。

I have a C++/CLI library that calls many native C++ methods. I have read many threads stating that you should not mix managed and unmanaged code. I couldnt find any that says how to avoid those switches and why it will cause a performance issue. Can someone share best practices.

推荐答案

使用C ++ / CLI的唯一原因是它支持混合管理和本地代码。如果一切都被管理,那么使用C#或VB,如果一切都是原生的,然后使用C或C ++。或任何你喜欢的语言。显然避免混淆是荒谬的。

The only reason to use C++/CLI is for its support of mixing managed and native code. If everything is managed then use C# or VB, if everything is native then use C or C++. Or whatever language you prefer. Clearly avoiding mixing is nonsensical.

有少量的开销从管理到非管理。 C ++ / CLI编译器自动生成一个机器码,在堆栈上推送一个cookie,旨在防止垃圾收集器崩溃为非托管堆栈帧和错误解释指针作为托管对象引用。费用大约7纳秒,给或取。

There is a small amount of overhead going from managed to unmanaged. The C++/CLI compiler auto-generates a bit of machine code that pushes a 'cookie' on the stack, designed to prevent the garbage collector from blundering into unmanaged stack frames and mis-interpreting pointers on that frame as managed object references. Costs about 7 nanoseconds, give or take.

这篇关于混合模式C ++ / CLI性能注意事项 - 最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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