473,378 Members | 1,372 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,378 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.

Nov 16 '05 #1
7 1928
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.
Nov 16 '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?
Nov 16 '05 #3
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?
Nov 16 '05 #4
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"
Nov 16 '05 #5
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"
Nov 16 '05 #6
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.
Nov 16 '05 #7
....
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.
Nov 16 '05 #8

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...
5
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....
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...
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...
12
by: doug | last post by:
I understand the basics of what managed code offers and that you open yourself up to security issues if you allow unmanaged code. We already have a decent amount of VB6 code to include COM DLLs. ...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.