混合模式慢? [英] Mixed Mode Slow?

查看:52
本文介绍了混合模式慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试混合模式项目,但我遇到速度问题。


我正在使用DLL并从C#链接到它。我以为我会尝试将C#功能和原始非托管代码粘贴到混合模式项目中。


它有效,但它是'非常慢。所有优化设置都是

相同。 DLL中的所有代码都是在/ clr关闭的情况下编译的。只有那些在C#中的位已经在托管C ++中重写了(我已经检查过它们了 - 它们不是原因)。


然而它现在比现在慢了五倍。


任何想法或者我应该回到最初的设计?


Jos

I''ve been trying a mixed mode project but I''m having speed problems.

I was using a DLL and linking into it from C#. I thought I''d try and stick
the C# functionality and the raw unmanaged code into a mixed mode project.

It works but it''s incredibly slow. All the optimization settings are the
same. All the code which was in the DLL is compiled with the /clr off. Only
the bits which were in C# have been re-written in managed C++ (and I''ve
checked them - they''re not the cause).

However it''s now five times slower than it was.

Any ideas or should I just go back to the original design?

Jos

推荐答案

Jos,
Jos,
我''我一直在尝试混合模式项目,但我遇到速度问题。

我正在使用DLL并从C#链接到它。我以为我会尝试将C#功能和原始的非托管代码粘贴到混合模式项目中。

它可以工作,但速度非常慢。所有优化设置都相同。 DLL中的所有代码都是在/ clr关闭的情况下编译的。
只有C#中的位已经在托管C ++中重写(我已经检查了它们 - 它们不是原因)。

然而它现在比它慢了五倍。

任何想法或者我应该回到最初的设计?
I''ve been trying a mixed mode project but I''m having speed problems.

I was using a DLL and linking into it from C#. I thought I''d try and stick
the C# functionality and the raw unmanaged code into a mixed mode project.

It works but it''s incredibly slow. All the optimization settings are the
same. All the code which was in the DLL is compiled with the /clr off. Only the bits which were in C# have been re-written in managed C++ (and I''ve
checked them - they''re not the cause).

However it''s now five times slower than it was.

Any ideas or should I just go back to the original design?




它很可能很大程度上取决于你在做什么。例如:你的MC ++包装器和非托管C ++库之间的

接口非常好吗?b $ b chatty?如果是这样,那将导致过多的托管 - >非托管 - >管理

转换,这可能会很昂贵。您可以通过更加精细地使用

界面来避免这种情况,有时甚至可以使用/ clr编译一些

非托管代码。


-

Tomas Restrepo
to****@mvps.org


Thomas
Thomas
它可能很大程度上取决于你在做什么。例如:你的MC ++包装器和非托管C ++库之间的接口非常好吗?如果是这样,那将导致过多的托管 - >非托管 - >托管转换,这可能代价高昂。您可以通过更加精细地使用
界面来避免这种情况,有时甚至可以使用/ clr编译一些非托管代码。
It might very well depend a lot on what you''re doing. For example: is the
interface between your MC++ wrapper and the unmanaged C++ library very
chatty? If so, that will cause too many managed->unmanaged->managed
transitions, which can be costly. You can avoid this by making your
interface more granular, and sometimes even by compiling some of your
unmanaged code with /clr.




谢谢。但是,我不认为这是问题所在。它是一个非常厚实的

接口,转换次数非常有限。我也沿着这些线做了一些

的实验,这些表明转换中的问题不是



我唯一能想到的是 - 或者 - 关闭clr是有时会忽略
- 或者 - 我正在应用的优化是被忽略的
。感觉就像我正在运行调试版本。非常奇怪。


出于兴趣,我将整个事情编译为托管。非常令人印象深刻的是

它甚至没有杂音就能编译。但是......它慢了十倍 - 哎哟!


我确信这一定是可能的,所以我认为我的下一步是编译

将本机代码作为库并将其导入到我的混合模式项目中。如果

不起作用那么我就不知道了。


感谢所有建议。


Jos



Thanks. However I don''t think this is the issue. It''s a very chunky
interface and the number of transitions is very limited. I did also do some
experiments along these lines and these indicated that the problem was not
in the transitions.

The only thing I can think of is - either - that turning off the clr is
being ignored sometimes - or - that the optimizations I''m applying are being
ignored. It feels like I''m running a debug version. Very odd.

Out of interest I compiled the whole thing as managed. Very impressive that
it compiles without even a murmur. But... it was ten times slower - ouch!

I''m convinced this must be possible so I think my next step is to compile
the native code as a library and import that into my mixed mode project. If
that doesn''t work then I just don''t know.

All suggestions gratefully received.

Jos


否 - 与以前完全一样。慢了五倍。


我不得不关闭一些优化,因为它们与

CLR标志不兼容。他们真的可以做出那么大的差异吗?


这是一个复杂的真实世界的应用程序,而不是一个演示所以我会认为

像程序优化可能会相差10%不是

500%。


来自MS的任何人都可以发表评论。


Jos
No - exactly the same as before. Still five times slower.

I had to turn off some optimizations because they were incompatible with the
CLR flag. Can they really make that much difference?

This is a complex real world app not a demo so I would have thought that
things like whold program optimization might make a difference of 10% not
500%.

Anyone from MS care to comment.

Jos


这篇关于混合模式慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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