473,597 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1525
> 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.

"JoeProgram mer" 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
741
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 managed point-of-view I've noticed that: 1) for each managed and unmanaged C function (not C++ classes) I get a public managed static method (defined on a 'Global Functions' class) in the generated assembly with an export name of the form...
5
2845
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. 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...
4
7170
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 functions in a C++ DLL. My first question is, if I insert a C++ project into my C# solution, how will VS.NET know that I want it to be unmanaged code? I intend to be calling the DLLs functions using DllImport. I've heard that you can have unmanaged...
3
3497
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
5717
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 collected. I also noticed that when replaced some of the existing MFC dialogs with managed winforms that everything is still running in the same app domain.( No context change) So my question is this, what are the performance differences in using...
13
5035
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 use that dll from pure unmanaged code (for example inherit from classes in that dll). Is something like that possible. I heared something called ManWarp tried that approach. If it is possible, how can I do that. Maybe there is a small litttle
12
1617
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. If we put wrappers around some of our code or leave some "asis" what makes our existing production code 'evil' just because it is now considered 'unmanaged'? It may seem like a simple niave question, but the definitions for managed and...
9
3111
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 this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
20
2288
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 have found hasnt been encouraging... I found that the *quickest* way is to use a struct to retrieve fixed length packets out of the file, but structs get placed on the stack! In one of the books I read, the stack is only about 1mb, so I would...
0
7893
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8276
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8259
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
3889
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.