Groups | Blog | Home
all groups > dotnet general > november 2004 >

dotnet general : Overhead in transition between managed/unmanaged code



_BNC
11/8/2004 8:24:06 PM
I've been adapting an older unmanaged C++ legacy app to C#---with limited
success. The original app made use of an older, but straightforward, C
DLL that worked efficiently under the VC++ 6 model.

To adapt to C#, I've wrapped the older DLL calls in an unmanaged C++
class which pretty much just parallels the original function calls and
encapsulates the more ragged aspects (handles, etc).

Then in turn, I wrapped the unmanaged C++ class in a managed C++ class.

All tedious but not real tricky. The C# code seems happy to instantiate
and call the managed C++ class. Preliminary test code executes with no
memory leaks and all execution paths seem intact.

The problem: The internal C DLL has functions that run in a thread.
That thread does not seem to run efficiently in the final C# program.
It's tough to gauge a difference in terms of exec time, but the C DLL's
time-critical code is no longer reliable.

Two reasons occurred to me:

1: The exec-time transition between the C#/C++Managed/C++ Unmanaged code
is very slow. I mean *very* slow. The older app runs fine on older
generation Pentiums.

2: The threading model in the managed code is significantly different in
some way that is affecting the underlying C code.

Ideas or random speculation is welcome.

-----

PS: Is there a code profiler that would be useful for this? The fact that
the code transitions from managed to unmanaged seems tough to handle.
richlm
11/9/2004 11:18:27 AM
Just a 'shot in the dark'...try hosting your c/c++ code as a component in
COM+ and call it through System.EnterpriseServices. That way you move your
time-critical thread(s) into an "unmanaged" process, which is (presumably)
more deterministic than one managed by the CLR.

For profiling you might try DevPartner Studio from Compuware - you should be
able to get hold of a copy for evaluation.

_BNC
11/9/2004 6:36:46 PM
[quoted text, click to view]

Hey, I'll try anything. Do you happen to know of any example code that
illustrates this?

richlm
11/10/2004 11:15:59 AM
Sorry don't know of any examples, but you might find some useful info/links
here:

"Improving .NET Application Performance and Scalability"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenet.asp
In particular:
a.. Chapter 7, "Improving Interop Performance"
a.. Chapter 8, "Improving Enterprise Services Performance"

_BNC
11/12/2004 8:25:18 PM
[quoted text, click to view]

Thanks for the link, Rich. That should be a great start.

_BNC
11/14/2004 10:51:23 PM
....
[quoted text, click to view]

You know, this brings up an interesting question: How much overhead is
involved in calling back and forth between managed/unmanaged code?
I had expected very little. Any opinions on this? I'm not looking for
hard stats, just subjective experience.

AddThis Social Bookmark Button