473,383 Members | 1,866 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,383 software developers and data experts.

managed/unmanaged code - can I efficiently run both in the same ap

A couple of questions re. managed vs. unmanaged code.
1. I know this depends on the app, but how much faster is unmanaged code
vs. managed code? Is there an average figure for this?
2. Is it as simple as using a #pragma to convert from unmanaged to managed?
And if so, can I simply change my existing code to managed with the #pragma
wherever I want to eliminate transitions, or are there issues with this?

--
JoeProgrammer
I'm good. That's why I keep asking you guys questions.
Nov 17 '05 #1
3 1503
> A couple of questions re. managed vs. unmanaged code.
1. I know this depends on the app, but how much faster is unmanaged code
vs. managed code? Is there an average figure for this?
The code I use has about 5% difference in speed.
It appears that managed code (C#) compiles similar like if you would have a
none-optimized compile of the C++ code.

The things is to avoid calles between managed/unmanaged too much since you
lose transition speed.
Basically I discoverd that in som parts of your code it will runn slower
while other parts will run faster.
I can only advice you to test your specific type of code.
2. Is it as simple as using a #pragma to convert from unmanaged to managed? And if so, can I simply change my existing code to managed with the #pragma wherever I want to eliminate transitions, or are there issues with this?

Not exactly.

For the none-MFC code:
But porting from unmanaged C++ to managed C++/C# is very easy, just copy and
paste, then search and replace and remove all deletes and in 90% of the time
it just runs without need of change.

For the MFC code (like windows dialog boxes, Sendmessage()...) this is going
to be a rewrite.
But luckily, Winforms is so user friendly compared to MFC that recreatign
the forms from scracht wil be really fun.

Only one thing I have to warn you. The .NET way has a different philosophy
than the MFC way, so you might have a hard time to change your programming
style. You will probably stumble om some stupid stuff like converting from
string to int and back. It is done different in the .NET way, but in my
opinion very logical. Once you know it. ;-) Also the security model is
integrated into the managed code. For example a default managd program has
default no access to a LAN drive. As a programmer you mist activate this
part, and also the user that installs that program must give right s for
that program to access the LAN drive. Luckily this can be easily configured
if your installer program, so the user does not need to be an expert in
administration. This took me a few months to find the good way of doing, but
it works fine.


Nov 17 '05 #2
Managed code may only be a bit slower when running in Release mode, buts its
much much much slower to link and debug.
If you are converting a large c++ project to managed c++ its almost
unusable, unless youv'e got a ****-hot PC.
It does a full link every time (see
http://www.dotnet247.com/247referenc...36/183691.aspx)
and debugging is unbelieveably slow.
They've said they "may" be sorting some of these problems out in Visual
Studio 2005.

"JoeProgrammer" wrote:
A couple of questions re. managed vs. unmanaged code.
1. I know this depends on the app, but how much faster is unmanaged code
vs. managed code? Is there an average figure for this?
2. Is it as simple as using a #pragma to convert from unmanaged to managed?
And if so, can I simply change my existing code to managed with the #pragma
wherever I want to eliminate transitions, or are there issues with this?

--
JoeProgrammer
I'm good. That's why I keep asking you guys questions.

Nov 17 '05 #3
> Managed code may only be a bit slower when running in Release mode, buts
its
much much much slower to link and debug.
If you are converting a large c++ project to managed c++ its almost
unusable, unless youv'e got a ****-hot PC.

I don't know about the C++, but in C# it is lightning fast.
What I tend to do is to use C# for pure managed functions since I can
program much faster, no slow compile and link time, much better compile
error reports, and no link errors, and it is fully compatible with managed
C++. And The parts that needs managed/unmanage C++ is done in C++.

And C++ and C# are very close on the syntax level. converting C# to C++ and
back is very easy to do.
Nov 17 '05 #4

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....
4
by: repstat | last post by:
Hi I have a project which is going to be doing some string manipulation which needs to be pretty fast. The user interface is going to be written in C#. I am going to write the string handling...
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...
4
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage...
13
by: bonk | last post by:
Hello, I am trying to create a dll that internally uses managed types but exposes a plain unmanaged interface. All the managed stuff shall be "wrapped out of sight". So that I would be able to...
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...
20
by: =?Utf-8?B?VGhlTWFkSGF0dGVy?= | last post by:
Sorry to bring up a topic that is just flogging a dead horse.... but... On the topic of memory management.... I am doing some file parcing that has to be done as quick as posible, but what I...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.