>> What I'm now struggling to understand is if I could incur performance
>> penalties by calling an unmanaged function (converted to unmanaged
[quoted text clipped - 4 lines]
> often you're doing it as to whether it'd be significant in your
> situation.
And most of the overhead is dealing with data. If you're passing built-in
types like int or double, virtually no cost at all. Pinning arrays will be
a little more expensive, and much more if they are still pinned during a
garbage collection. Marshalling COM objects will probably be the worst.
> Have a look at the MSDN topic titled "Performance Considerations for
> Interop (C++)" for more information. It's rather sketchy but I don't
> recall reading any in-depth documentation of the thunking involved.
>
> Dave
Henri.Chinasque@googlemail.com - 24 Jul 2008 18:00 GMT
Hi guys,
thanks for your responses, a big help. I then got curious and used
reflector to have a look at the differences between native classes
preceded by pragma unmanaged or managed. The funny thing is that I
couldn't see any differences. I get either
this: (preceded by #pragma unmanaged)
[StructLayout(LayoutKind.Sequential, Size=1), NativeCppClass,
DebugInfoInPDB, MiscellaneousBits(0x40), CLSCompliant(false)]
public struct UsesPragmaManaged
{
}
or this: (preceded by #pragma unmanaged)
[StructLayout(LayoutKind.Sequential, Size=1), MiscellaneousBits(0x40),
NativeCppClass, CLSCompliant(false), DebugInfoInPDB]
public struct UsesPragmaUnmanaged
{
}
Both classes contain an identical method (which is missing in
reflector),that when called runs 4 times faster in #pragma unmanaged.
What I don't understand is how the UsesPragmaManaged code is handled
by the CLR, and why it is running slower, when it seems to be
identical.
Much thanks,
HC
> >> What I'm now struggling to understand is if I could incur performance
> >> penalties by calling an unmanaged function (converted to unmanaged
[quoted text clipped - 17 lines]
>
> - Show quoted text -
Henri.Chinasque@googlemail.com - 24 Jul 2008 18:13 GMT
Hi guys,
thanks for your responses, a big help. I then got curious and had a
look in Reflector to see exactly what is happening with my classes
that are preceded by either pragma managed or unmanaged. The strange
thing is that they look identical, either:
(preceded by #pragma managed)
[StructLayout(LayoutKind.Sequential, Size=1), NativeCppClass,
DebugInfoInPDB, MiscellaneousBits(0x40), CLSCompliant(false)]
public struct UsesPragmaManaged
{
}
- or - (preceded by #pragma unmanaged)
[StructLayout(LayoutKind.Sequential, Size=1), MiscellaneousBits(0x40),
NativeCppClass, CLSCompliant(false), DebugInfoInPDB]
public struct UsesPragmaUnmanaged
{
}
Both classes contain an identical method (which is missing from both
in Reflector), that runs 4 times faster with the UsesPragmaUnmanaged
class. This is all fine and good, but I don't understand how the CLR
is handling the UsesPragmaManaged class - it doesn't look any
different...
Much thanks,
HC
> >> What I'm now struggling to understand is if I could incur performance
> >> penalties by calling an unmanaged function (converted to unmanaged
[quoted text clipped - 17 lines]
>
> - Show quoted text -
Mark Salsbery [MVP] - 24 Jul 2008 18:39 GMT
> Hi guys,
>
[quoted text clipped - 21 lines]
> Both classes contain an identical method (which is missing from both
> in Reflector), that runs 4 times faster with the UsesPragmaUnmanaged
4 times faster? What does this method do?
Mark

Signature
Mark Salsbery
Microsoft MVP - Visual C++
> class. This is all fine and good, but I don't understand how the CLR
> is handling the UsesPragmaManaged class - it doesn't look any
[quoted text clipped - 25 lines]
>>
>> - Show quoted text -
Henri.Chinasque@googlemail.com - 24 Jul 2008 20:20 GMT
here it is:
int simple(int n[], int count) {
int x=1;
for(int i=0;i<count;i++) {
int y=i;
for(int i=0;i<count;i++) {
y+=n[i];
}
x*=y;
}
return x;
}
n has a length of 80000 (this is also the value of count) and is
populated with random numbers. Same array is used for every call.
I could understand if it runs faster in native, what I don't
understand is how "native" classes are handled by the CLR when they
are compiled managed, i.e. why is the managed version running so much
more slowly when the code from Reflector looks the same as the
unmanaged version?
thanks again,
HC
On Jul 24, 11:39 am, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nospam> wrote:
> <Henri.Chinas...@googlemail.com> wrote in message
>
[quoted text clipped - 67 lines]
>
> - Show quoted text -