附加调试器时,从.Net代码调用C ++ dll的速度非常慢 [英] Calling C++ dll from .Net Code is Excruciatingly Slow when a Debugger is Attached

查看:230
本文介绍了附加调试器时,从.Net代码调用C ++ dll的速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2008编译和调试我的代码.在我的应用程序中,前端是C#,后端是C ++.我通过互操作访问C ++代码.

I am using VS 2008 to compile and debug my code. In my application, the front end is C#, the backend is C++. I access the C++ code via interop.

我注意到的一件事是,如果我按F5键,并且链接了本机代码的调试版本,则运行本机代码将花费20秒钟以上.如果我链接了本机代码的发行版,则运行它所需的时间将减少到7-8秒.

One thing I notice is that if I press F5, and I link in the debug version of the native code, it would take more than 20 seconds to run the native code. If I link in the release version of the native code, the time needed to run it is cut down to 7-8 seconds.

如果我没有连接VS 2008调试器(即,我单击IDE外部的exe),并且我链接了C ++代码的发行版,则只需1秒即可运行C ++代码.

And if I don't have the VS 2008 debugger attached ( i.e., I click on the exe outside of the IDE), and I link in the release version of the C++ code, it takes only 1 second to run the C++ code.

请注意,对于所有测试,C ++代码的输入始终始终相同.

Note that for all the testing, the input to C++ code is always always the same.

当然,与调试器的附件和调试版本相关的开销很大.但是性能差异太大.我有什么想念的还是可以调整的?

For sure, there are some overheads associated with the attachment of debugger, and debug build. But the difference in performance is just too big. Could there be anything I miss or I can tune up?

我发现这很令人困惑;根据我的经验,无论您是使用调试器运行还是以调试模式运行,C#都不会带来太多开销.

I find that this is very puzzling; C# in my experience doesn't introduce this much overhead, regardless of whether you are running with a debugger, or whether you are running in debug mode.

推荐答案

我最好的猜测是,加载调试符号会使您减速.我已经看到完全非托管的C ++项目会发生完全相同的事情,这些项目设置为自动为所有Windows系统库加载符号文件.确保您没有自动加载调试符号:

My best guess would be that loading the debugging symbols is what's slowing you down. I've seen the exact same thing happen with purely unmanaged C++ projects that are set to automatically load the symbol files for all of the Windows system libraries. Make sure that you're not automatically loading debugging symbols:

  1. 在工具"菜单中,单击选项".
  2. 将调试"类别扩展到左侧,然后选择符号"子类别.
  3. 选中标有仅在手动加载符号时才搜索以上位置"的复选框.


此外,请考虑混合模式调试非常慢.


Additionally, consider that mixed-mode debugging is extremely slow.

如果您不需要进入C ++ DLL中的代码的功能,则可以尝试关闭项目属性中的启用非托管代码调试"选项:

If you don't need the ability to step into the code in the C++ DLL, you can try turning off the "Enable unmanaged code debugging" option in your project's properties:

  

  

这篇关于附加调试器时,从.Net代码调用C ++ dll的速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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