473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Overhead in transition between managed/unmanaged code

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.

Jul 21 '05 #1
5 2829
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.
Jul 21 '05 #2
On Tue, 9 Nov 2004 11:18:27 +0100, "richlm" <ri*****@h0tmai1.com> wrote:
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.


Hey, I'll try anything. Do you happen to know of any example code that
illustrates this?
Jul 21 '05 #3
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/de...l/scalenet.asp
In particular:
a.. Chapter 7, "Improving Interop Performance"
a.. Chapter 8, "Improving Enterprise Services Performance"
Jul 21 '05 #4
On Wed, 10 Nov 2004 11:15:59 +0100, "richlm" <ri*****@h0tmai1.com> wrote:
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/de...l/scalenet.asp
In particular:
a.. Chapter 7, "Improving Interop Performance"
a.. Chapter 8, "Improving Enterprise Services Performance"


Thanks for the link, Rich. That should be a great start.
Jul 21 '05 #5
....
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.

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.

On Wed, 10 Nov 2004 11:15:59 +0100, "richlm" <ri*****@h0tmai1.com> wrote:
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/de...l/scalenet.asp
In particular:
a.. Chapter 7, "Improving Interop Performance"
a.. Chapter 8, "Improving Enterprise Services Performance"


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.
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
3
by: Mike | last post by:
I have been developing ASP applications for quite a while now. Most of the apps that I deploy are a typical n-tier setup. ASP GUI on a web server, Business and Data Components written in VB6...
7
by: _BNC | last post by:
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....
1
by: Eric Twietmeyer | last post by:
Hello, I'm starting to investigate cs, managed c++ and interoperating with a very large unmanaged code base. We are going to use Windows Forms (written in cs) to replace our old fashioned GUI. ...
4
by: Peter Olcott | last post by:
I want to be able to make my .NET applications run just as fast as unmanaged C++. From my currently somewhat limited understanding of the .NET framework and the C# language, it seems that...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
3
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
25
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.