473,396 Members | 2,039 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,396 software developers and data experts.

Performance of pure native C++ class in a managed C++/CLI DLL comp

I have a class that is writen in unmanaged pure native C++.
This class files (h and cpp) are inserted to a managed C++ (VC++ 2005,
C++/CLI) DLL compoenet.
This DLL compoenet is used in a C# application.

My question is:
Does the performance of the unmanaged pure native C++ class described above
is the same if it was a in a pure unmanaged native C++ DLL component?
--
Thanks
Sharon
Jun 23 '07 #1
5 7227
My question is:
Does the performance of the unmanaged pure native C++ class described
above
is the same if it was a in a pure unmanaged native C++ DLL component?
Yes. The performance of that native class will be the same as if it was in a
native app.
The only thing you have to keep in mind is that every time there is a
native - managed transition, the data is marshalled so if you have lots of
transitions per second, performance will suffer.

--
Kind regards,
Bruno van Dooren MVP - VC++
http://msmvps.com/blogs/vanDooren
Jun 23 '07 #2
Bruno van Dooren [MVP - VC++] wrote:
>My question is:
Does the performance of the unmanaged pure native C++ class described
above
is the same if it was a in a pure unmanaged native C++ DLL component?

Yes. The performance of that native class will be the same as if it
was in a native app.
.... that is assuming, of course, that the .cpp file in question is still
compiled as native code! Just dropping the .cpp and .h into a managed C++
project will most likely result in the code being compiled as managed
(managed code, unmanaged data). In order to ensure that the class is still
unmanaged, it's necessary to bracket #includes of the .h file with something
along the lines of...

#pragma managed(push,off)
#include "myNativeClass.h"
#pragma managed(pop)

This must be done in every managed compiland that #includes this header (or
do it in the header itself, if you don't mind modifying it, or make another
wrapper-header to do it - you get the idea).

Also check the project settings to make sure that the .cpp file containing
the natice class implementation is NOT compiled with /CLR.
The only thing you have to keep in mind is that every time there is a
native - managed transition, the data is marshalled so if you have
lots of transitions per second, performance will suffer.
Yep, that too!

-cd
Jun 23 '07 #3

The DLL component is CLI supported and there is some code in this component
that uses the .NET syntax and Frameworks.
So what setting should I do in the project setting for some of my
classes/files to be complied as an unmanaged pure native C++?

Ok, in every file that uses the myNativeClass.h, I will do it like that:

#pragma managed(push,off)
#include "myNativeClass.h"
#pragma managed(pop)

But what about another unmanaged pure native C++ class that is used by the
first unmanaged pure native C++ class?
Do I need also to add the #pragma managed(push,off) and #pragma managed(pop)
in the unmanaged pure native C++ that uses another unmanaged pure native C++
files?

Maybe it's better to simply put all the unmanaged pure native C++
classes/files in a separate unmanaged pure native DLL component, and use the
DLL in another managed C++/CLI DLL component?

What is the safest way to do it? Or event better; what is the deployment
that will make the unmanaged pure native C++ code run the fastest?
-----
Thanks
Sharon
Jun 23 '07 #4
Sharon wrote:
The DLL component is CLI supported and there is some code in this
component that uses the .NET syntax and Frameworks.
So what setting should I do in the project setting for some of my
classes/files to be complied as an unmanaged pure native C++?
You can set /CLR on or off in each .cpp file individually. Turn it on for
the whole project,. as you have done, then turn it off for the files
containing only native (unmanaged) code. When you have the VC++ procject
properties dialog open, you can still click on files/projects in the
solution explorer to change the scope that you're working on. Click on the
unmanaged .cpp file to set options for just that file.
>
Ok, in every file that uses the myNativeClass.h, I will do it like
that:

#pragma managed(push,off)
#include "myNativeClass.h"
#pragma managed(pop)

But what about another unmanaged pure native C++ class that is used
by the first unmanaged pure native C++ class?
Doesn't matter. That's why it's good practice to use the push/pop features
of #pragma managed (and a number of other compiler pragmas, for that
matter). It's safe to wrap everywhere, and the contents of the header file
will always be interpreted as unmanged. For portability/reuse reasons, you
might not want to do the wrapping when the #include is in an unmanged file,
but it does not harm to do so.
Do I need also to add the #pragma managed(push,off) and #pragma
managed(pop) in the unmanaged pure native C++ that uses another
unmanaged pure native C++ files?

Maybe it's better to simply put all the unmanaged pure native C++
classes/files in a separate unmanaged pure native DLL component, and
use the DLL in another managed C++/CLI DLL component?
That is a common solution. If you have a lot of native code to integrate,
it may well be the better solution. Design a pure C or COM interface to the
native code, and then use that component from your managed code.
>
What is the safest way to do it? Or event better; what is the
deployment that will make the unmanaged pure native C++ code run the
fastest?
Done correctly, either approach will be just as safe and just as performant.
If anything, the performance factors probably lean slightly towards the
mixed-mode DLL, since the compiler-interop can work at the C++ level and you
don't have to force your API into C or COM.

-cd
Jun 24 '07 #5
>Maybe it's better to simply put all the unmanaged pure native C++
classes/files in a separate unmanaged pure native DLL component, and
use the DLL in another managed C++/CLI DLL component?

That is a common solution. If you have a lot of native code to integrate,
it may well be the better solution. Design a pure C or COM interface to
the native code, and then use that component from your managed code.
>>
What is the safest way to do it? Or event better; what is the
deployment that will make the unmanaged pure native C++ code run the
fastest?

Done correctly, either approach will be just as safe and just as
performant. If anything, the performance factors probably lean slightly
towards the mixed-mode DLL, since the compiler-interop can work at the C++
level and you don't have to force your API into C or COM.
It's probably preferable to make the native code a static library instead of
a DLL. Then you get the benefits of a separate build environment and the
benefits of mixed-mode.
>
-cd

Jun 25 '07 #6

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

Similar topics

4
by: Prawit Chaivong | last post by:
Hi, gurus The Ctor & Dtor of pure virtual class (interface class) should be IMyClass() = 0; or IMyClass() { } Thank in advance
3
by: Stephen R. G. Fraser | last post by:
Are or will delegating constructors (constructors that can call sibling constructors) be available for ref classes or only for native classes? The CLI/C++ specs seems to say that it is a native...
9
by: Herby | last post by:
Is possible to have a managed method within a Native(un-managed) class within a \clr project? E.g. class myClass { public: #pragma managed void myMethod(void);
9
by: Lonewolf | last post by:
Hi everyone.. I was trying to implement callback fucntions in native codes in my VC8 class, and referred to some online codes which use native class nested within managed class. basically of the...
8
by: quortex | last post by:
Hi all, I have a native class which has a single instance controlled via the singleton pattern. I need to call this from both native C++ and from mixed mode visual studio 2005 c++ CLI. At...
4
by: skishorev | last post by:
and what is object delagation, and how it can implemented?
4
by: mikewse | last post by:
How can I subclass a native class to get my own class with all the function of the native clas, plus correct instanceof behaviour? The scenario I'm thinking of is something like function...
0
by: DaTurk | last post by:
Hi, I need to have a native class hold on to a managed function pointer. Not a unmanaged class in a manged block. I mean an unmanaged class in an unmanaged block via #pragma unmanaged. I'm...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
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.