473,396 Members | 1,774 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.

Managed function vs unmanaged function

Hello everybody!

I have a question. Anybody knows why managed function calls faster in MC++
rather than unmanaged function (defined with #pragma umanaged)? The
differences is about 4 times slower.

Thanks for your answers!
Z-Mechanic.
Nov 17 '05 #1
7 1362
Could you send us some code with compiler switches you used so that we can
do performance comparisons ?
For eg, is the function you are trying to call virtual ? Is it called from a
managed callsite ? Did you compile it pure?
Thanks,
Kapil

"Z-Mechanic" <Z-********@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Hello everybody!

I have a question. Anybody knows why managed function calls faster in MC++
rather than unmanaged function (defined with #pragma umanaged)? The
differences is about 4 times slower.

Thanks for your answers!
Z-Mechanic.

Nov 17 '05 #2
It can be down to managed / unmanaged transitions, depend on what's going on
inside the function, and lots of other factors. If you could post the
function along with its calling context, someone will be able to give you a
definitive explanation. We didn't actually find a significant performance
hit when we eradicated all the "#pragma unmanaged" directives from our maths
code, and we found that performance could be greatly affected by unnecessary
managed/unmanaged transitions. Unless you've got a really good reason to use
#pragma unmanaged, and unless that chunk of code is fairly large and doesn't
call back into managed code, you might be better leaving it all as managed
code.

Steve

"Z-Mechanic" <Z-********@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Hello everybody!

I have a question. Anybody knows why managed function calls faster in MC++
rather than unmanaged function (defined with #pragma umanaged)? The
differences is about 4 times slower.

Thanks for your answers!
Z-Mechanic.

Nov 17 '05 #3
Hi!

I have a math library that makes 3D matrices (4x4) multiplication. After
compillation it placing in same assembly. When I compile that source with
#pragma unmanaged it works 2 times faster rather tham managed. It's fine.

But... Simple test. Source code of test files listed below. Simply call
TestCPP::Class1::Test(0);

---- Begin of TestCPP.h ----
// TestCPP.h
#pragma once

using namespace System;

int vvv(int i);

int vvv1(int i);
int vvv2(int i);
int vvv3(int i);
int vvv4(int i);
int vvv5(int i);

namespace TestCPP
{
public __gc class Class1
{
public:
static void Test(int v)
{
int m = 0;

for (int j = 0; j < 100; j++)
for (int i = 0; i < 1000000; i++)
{
m = vvv( i );
// m = vvv1( i );
// m = vvv2( m );
// m = vvv3( m );
// m = vvv4( m );
// m = vvv5( m );
}

m++;
}
};
}
---- End of TestCPP.h ----

---- Begin of TestCPP.cpp ----
// This is the main DLL file.

#include "stdafx.h"

#include "TestCPP.h"

#pragma unmanaged

int vvv(int i)
{
i = vvv1( i );
i = vvv2( i );
i = vvv3( i );
i = vvv4( i );
i = vvv5( i );

return i;
}

int vvv1(int i)
{
i++;
return i;
}

int vvv2(int i)
{
i++;
return i;
}

int vvv3(int i)
{
i++;
return i;
}

int vvv4(int i)
{
i++;
return i;
}

int vvv5(int i)
{
i++;
return i;
}
#pragma managed
---- End of TestCPP.cpp ----

------------------------------------------------------------------------------------------------

It makes the same. But when you uncomment calls vvv1, vvv2, vvv3, vvv4, vvv5
and comment vvv you will get execution much longer that present now.
Nov 17 '05 #4
Hi!

I have a math library that makes 3D matrices (4x4) multiplication. After
compillation it placing in same assembly. When I compile that source with
#pragma unmanaged it works 2 times faster rather tham managed. It's fine.

But... Simple test. Source code of test files listed below. Simply call
TestCPP::Class1::Test(0);

---- Begin of TestCPP.h ----
// TestCPP.h
#pragma once

using namespace System;

int vvv(int i);

int vvv1(int i);
int vvv2(int i);
int vvv3(int i);
int vvv4(int i);
int vvv5(int i);

namespace TestCPP
{
public __gc class Class1
{
public:
static void Test(int v)
{
int m = 0;

for (int j = 0; j < 100; j++)
for (int i = 0; i < 1000000; i++)
{
m = vvv( i );
// m = vvv1( i );
// m = vvv2( m );
// m = vvv3( m );
// m = vvv4( m );
// m = vvv5( m );
}

m++;
}
};
}
---- End of TestCPP.h ----

---- Begin of TestCPP.cpp ----
// This is the main DLL file.

#include "stdafx.h"

#include "TestCPP.h"

#pragma unmanaged

int vvv(int i)
{
i = vvv1( i );
i = vvv2( i );
i = vvv3( i );
i = vvv4( i );
i = vvv5( i );

return i;
}

int vvv1(int i)
{
i++;
return i;
}

int vvv2(int i)
{
i++;
return i;
}

int vvv3(int i)
{
i++;
return i;
}

int vvv4(int i)
{
i++;
return i;
}

int vvv5(int i)
{
i++;
return i;
}
#pragma managed
---- End of TestCPP.cpp ----

------------------------------------------------------------------------------------------------

It makes the same. But when you uncomment calls vvv1, vvv2, vvv3, vvv4, vvv5
and comment vvv you will get execution much longer that present now.
Nov 17 '05 #5
This is related to exactly what I said; in your managed call, you go from
calling one unmanaged function to calling 5. When they're wrapped into a
single unmanaged function in the DLL, there's less managed -> unmanaged
transitions, and less DLL overheads. There was a nother thread on here a few
days ago about all this, and there's lots of info on the net.
I can't see much advantage making this unmanaged, to be honest - I doubt
you'll see a big performance increase.

Steve

"Z-Mechanic" <ZM*******@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
Hi!

I have a math library that makes 3D matrices (4x4) multiplication. After
compillation it placing in same assembly. When I compile that source with
#pragma unmanaged it works 2 times faster rather tham managed. It's fine.

But... Simple test. Source code of test files listed below. Simply call
TestCPP::Class1::Test(0);

---- Begin of TestCPP.h ----
// TestCPP.h
#pragma once

using namespace System;

int vvv(int i);

int vvv1(int i);
int vvv2(int i);
int vvv3(int i);
int vvv4(int i);
int vvv5(int i);

namespace TestCPP
{
public __gc class Class1
{
public:
static void Test(int v)
{
int m = 0;

for (int j = 0; j < 100; j++)
for (int i = 0; i < 1000000; i++)
{
m = vvv( i );
// m = vvv1( i );
// m = vvv2( m );
// m = vvv3( m );
// m = vvv4( m );
// m = vvv5( m );
}

m++;
}
};
}
---- End of TestCPP.h ----

---- Begin of TestCPP.cpp ----
// This is the main DLL file.

#include "stdafx.h"

#include "TestCPP.h"

#pragma unmanaged

int vvv(int i)
{
i = vvv1( i );
i = vvv2( i );
i = vvv3( i );
i = vvv4( i );
i = vvv5( i );

return i;
}

int vvv1(int i)
{
i++;
return i;
}

int vvv2(int i)
{
i++;
return i;
}

int vvv3(int i)
{
i++;
return i;
}

int vvv4(int i)
{
i++;
return i;
}

int vvv5(int i)
{
i++;
return i;
}
#pragma managed
---- End of TestCPP.cpp ----

------------------------------------------------------------------------------------------------

It makes the same. But when you uncomment calls vvv1, vvv2, vvv3, vvv4,
vvv5
and comment vvv you will get execution much longer that present now.

Nov 17 '05 #6
Hi!

Greate thanks for explanations!

It was a test only to check perfomance on procedure calling. As I said
before I got a great increase of perfomance on a complex math functions when
I put my code to unmanaged.
Nov 17 '05 #7
Hi,

Yes, typically with complex instructions you will find performance
increases. It's just important to ensure that you're not constantly
transitioning between managed and unmanaged code, or you'll lose the
benefits. I'm sorry I can't find the explanation of all this; if you Google
for something like "Unmanaged managed code transition" you'll probably get
some info.

Steve

"Z-Mechanic" <ZM*******@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.com...
Hi!

Greate thanks for explanations!

It was a test only to check perfomance on procedure calling. As I said
before I got a great increase of perfomance on a complex math functions
when
I put my code to unmanaged.

Nov 17 '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...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
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. ...
7
by: Lev | last post by:
Hi, I have an unmanaged pointer to a class that I want to hold in a managed class. I pass the pointer (from unmanaged code) in the constructor of the managed class, and at that point it has...
2
by: Martin Zenkel | last post by:
Dear VS Team, using the Beta 2 of VS 2005 I've encontered the following problem. Let's assume threre are three Dll's, one unmanaged and two managed. In the unmanaged we put a simple unmanged...
1
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender,...
6
by: nicolas.hilaire | last post by:
Hi all, i'm not totally clear with some concepts about managed and unmanaged code. I'm asking myself some questions : - i've a MFC app, i want to use the framework dotnet by switching to...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
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...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
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
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...
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
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,...
0
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...
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,...

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.