473,805 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inlined functions in mixed mode C++

Hi,

We've found some pretty serious performance hits that we didn't expect in a
mixed mode C++ application. The number crunching bits of our algorithms are
compiled with #pragma unmanaged. They call a number of inline functions
elsewhere, and from the documentation my understanding was that inlined
function calls are supposed to be effectively replaced by their
implementation at compile time. This would mean that inline functions used
in a #pragma unmanaged function would also be compiled unmanaged.

However, having written a short test, this appears not to be the case -
putting #pragmas in the header affects how the inlined functions are
compiled (and affects running time enormously).

So given the code at the bottom of this post, my understanding would be the
following:
- Calling from a managed function, the first function should be as quick as
NumberCrunching _InlineFunction _InNoGCClass_Ma naged, which is compiled as
managed.
- Calling from an unmanaged function, the first should be as fast as
NumberCrunching _InlineFunction _InNoGCClass_Un managed, which is specified to
be unmanaged.

Given that it is apparently possible to influence how inlined functions are
compiled in the header, and that our inlined functions may be called from
both managed and unmanaged functions, what are we supposed to do? And
equally, how does all this apply to templated functions (which should be
compiled as they're used)? We're pretty sure that instead of the inlining
giving us good performance, it's causing masses of transitions between
managed / unmanaged processes. Any help would really be appreciated, as
would any links to info.

Thanks!

Steve

### CODE ###

__nogc class UnmanagedClass
{
public:
// This function isn't specified how to compile
__forceinline void
NumberCrunching _InlineFunction _InNoGCClass_Le ftToItsOwnDevic es()
{
for ( int i = 0 ; i < 1000000 ; i++ )
{
double d = sqrt( 69765.43556 ) * log( 9032425.543535 ) / sqrt( log
( exp( 3.65464 ) ) );
}
}

#pragma unmanaged
__forceinline void NumberCrunching _InlineFunction _InNoGCClass_Un managed()
{
for ( int i = 0 ; i < 1000000 ; i++ )
{
double d = sqrt( 69765.43556 ) * log( 9032425.543535 ) / sqrt( log
( exp( 3.65464 ) ) );
}
}

#pragma managed
__forceinline void NumberCrunching _InlineFunction _InNoGCClass_Ma naged()
{
for ( int i = 0 ; i < 1000000 ; i++ )
{
double d = sqrt( 69765.43556 ) * log( 9032425.543535 ) / sqrt( log
( exp( 3.65464 ) ) );
}
}
};
Nov 17 '05 #1
2 1286
Steve McLellan wrote:
Hi,

We've found some pretty serious performance hits that we didn't
expect in a mixed mode C++ application. The number crunching bits of
our algorithms are compiled with #pragma unmanaged. They call a
number of inline functions elsewhere, and from the documentation my
understanding was that inlined function calls are supposed to be
effectively replaced by their implementation at compile time. This
would mean that inline functions used in a #pragma unmanaged function
would also be compiled unmanaged.

However, having written a short test, this appears not to be the case
- putting #pragmas in the header affects how the inlined functions are
compiled (and affects running time enormously).

So given the code at the bottom of this post, my understanding would
be the following:
- Calling from a managed function, the first function should be as
quick as NumberCrunching _InlineFunction _InNoGCClass_Ma naged, which is
compiled as managed.
- Calling from an unmanaged function, the first should be as fast as
NumberCrunching _InlineFunction _InNoGCClass_Un managed, which is
specified to be unmanaged.

Given that it is apparently possible to influence how inlined
functions are compiled in the header, and that our inlined functions
may be called from both managed and unmanaged functions, what are we
supposed to do? And equally, how does all this apply to templated
functions (which should be compiled as they're used)? We're pretty
sure that instead of the inlining giving us good performance, it's
causing masses of transitions between managed / unmanaged processes.
Any help would really be appreciated, as would any links to info.


Separate your code into pure-native and pure-managed compilation units and
never use #pragma {un}managed. That should result in inlined IL versions of
your functions in the managed module(s) and inlined native versions in the
native modules. Templates should work out the same.

-cd
Nov 17 '05 #2
> Steve McLellan wrote:
Hi,

We've found some pretty serious performance hits that we didn't
expect in a mixed mode C++ application. The number crunching bits of
our algorithms are compiled with #pragma unmanaged. They call a
number of inline functions elsewhere, and from the documentation my
understanding was that inlined function calls are supposed to be
effectively replaced by their implementation at compile time. This
would mean that inline functions used in a #pragma unmanaged function
would also be compiled unmanaged.

However, having written a short test, this appears not to be the case
- putting #pragmas in the header affects how the inlined functions are
compiled (and affects running time enormously).

So given the code at the bottom of this post, my understanding would
be the following:
- Calling from a managed function, the first function should be as
quick as NumberCrunching _InlineFunction _InNoGCClass_Ma naged, which is
compiled as managed.
- Calling from an unmanaged function, the first should be as fast as
NumberCrunching _InlineFunction _InNoGCClass_Un managed, which is
specified to be unmanaged.

Given that it is apparently possible to influence how inlined
functions are compiled in the header, and that our inlined functions
may be called from both managed and unmanaged functions, what are we
supposed to do? And equally, how does all this apply to templated
functions (which should be compiled as they're used)? We're pretty
sure that instead of the inlining giving us good performance, it's
causing masses of transitions between managed / unmanaged processes.
Any help would really be appreciated, as would any links to info.
Separate your code into pure-native and pure-managed compilation units and
never use #pragma {un}managed. That should result in inlined IL versions

of your functions in the managed module(s) and inlined native versions in the
native modules. Templates should work out the same.


Hi Daniel,

Thanks - that's what we figured. Just what you need to realise a few weeks
before the project's meant to be completed :-)

Is this behaviour what you'd expect - i.e. is it what would happen with any
C++ compiler with regard to inlined functions? Or did the compiler team make
the decision to aim for easy portability at the expense of performance in
this case? IJW - but not fast :-)

Presumably it's still possible to link against a static LIB when building an
..NET assembly if I stick the unmanaged stuff in one?

Thanks again,

Steve
Nov 17 '05 #3

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

Similar topics

15
1494
by: Steven T. Hatton | last post by:
I know this is, to some extent, implementation dependent, but since the Standard specifies an inline specifier, there must be some "reasonable assumptions" I can make about what should happen when I inline a function. Suppose I have something like this (which, BTW is currently broken in Qt-4-rc1): inline QWidget* vBox(QWidget* parent) { QWidget* box = new QWidget(parent); QVBoxLayout* boxLayout = new QVBoxLayout(box);
8
3521
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
1
967
by: Jacobo Rodriguez Villar | last post by:
Hello, I'm writting an application using mixed mode with C++ and C++.NET, and I have a problem, if I put a breakpoint or try to enter (with step by step) into a virtual and unmanaged method, the debugger tell me: "There aren't source code avalaible for the current location", and the disassembler window appears. I can enter with the debugger into functions of the same file but these functions aren't virtual. I tried to put the debugger in...
2
2061
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 afterwards 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
8
2000
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid the usage of old style COM, my alternative is to expose my unmanaged interface through the CLI, to achieve that I have created a mixed mode DLL in which my unmanaged class are defined. When referencing the DLL just described in another mixed mode EXE...
10
1349
by: Serg | last post by:
Every time i am trying to step into virtual funtion debugger tells me "there is no source code available" and disassemble window appears. If function is non virtual debugger succefully steps into it and shows source code. Is there any compiler key that can fix it? Please help. Thanks in adv.
8
2325
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
9
3123
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
2
1553
by: newbie | last post by:
I happened to read boost library code and realized that most (the part I read) functions are inlined like: template <class Key> inline void Foo(const Key& k) { ... ... } Is there a strong reasoning behind this?
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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
10604
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
10356
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
10361
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
9179
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7644
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.