Re: Interop Marshalling Overhead - Newbie qn



Almost missed something in your original reply

If I'm hearing you correctly hear. If I apply a
SuppressUnmanagedCodeSecurityAttribute to my interop calls I could reduce the
interop access overhead by a factor of 4-5!

Now that's worth talking about! Will look into that one, since it could
make writing C# classes that directly call some Win32 APIs plausible.

Cheers,

Steve

"Willy Denoyette [MVP]" wrote:

>
> "steve" <steve@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:D6466C55-9356-4E43-AB08-410DA6325FEB@xxxxxxxxxxxxxxxx
> > Despite the suggestions I read in newsgroups and other places I get the
> > feeling that Interop marshalling does not actually carry that much
> > overhead
> > (we'll at least for simple marshalls).
> >
> > I'd like some feedback from someone in the know about which types carry
> > expensive marshalling penalties. No I'm not interested in COM et al.
> > Just
> > simple C style calls.
> >
> > I measured the performance of a typical C call natively (Win32) and with
> > interop using QueryPerformanceCounter, and I couldn't see any differences
> > in
> > the call latency.
> >
> > The C call was something like
> >
> > int GetDataFromXYZ(unsigned char *Data, int *pBytesToRead);
> >
> > ///////////////////////
> > //
> > // Here's the question
> >
> > Under what circumstances should I NOT use Interop marshalling to achieve
> > my
> > end?
> >
> > Cheers
> >
> > Steve
>
> There are two kind of overhead to consider when using PInvoke interop.
> 1. The call overhead
> 2. The marshaling overhead.
> 1. There is a fixed overhead of ~140 or ~30 native instructions per call,
> the first figure is the default, the second is the overhead left when you
> suppressed a security walk for the call into native code (see
> SuppressManagedCodeSecurityAttribute).
> 2. Is variable depending on the type a amount of data to be marshaled.
> Blittable types (int, byte, short, ...) don't carry additional overhead, but
> strings do carry a variable overhead depending on the length and their
> character encoding (ANSI/Unicode).
>
> I don't understand why you couldn't see any difference, sure without seeing
> any code and details about the way you measured, it's hard to tell why.
>
> Willy.
>
>
>
.



Relevant Pages

  • Re: Interop Marshalling Overhead - Newbie qn
    ... Interop Overhead ... In my application I'm quite comfortable with the interop ... Marshalling Overhead ... int GetDataFromXYZ; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Interop Marshalling Overhead - Newbie qn
    ... > SuppressUnmanagedCodeSecurityAttribute to my interop calls I could reduce ... Yes, that's right, SuppressUnmanagedCodeSecurityAttribute removes the ... security level. ... while for most others this overhead is simply ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ComInterop
    ... I would say that some of the main downsides of COM Interop is the overhead of marshalling your parameters to the COM component. ...
    (microsoft.public.dotnet.general)
  • Re: Garbage collectable pinned arrays!
    ... The OP is measuring the overhead of a GCHandle.Alloc, ... exactly what is done by GCHandle.Alloc with GCHandleType.Pinned, that's why he is measuring this methods overhead. ... But interop doesn't pin implicitely, it pins the arguments when needed. ... "Pointer Table" together with some ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: CCW overheads
    ... It's impossible to say with only that information if COM interop ... overhead will be an issue or not for you. ... Mattias Sjögren [MVP] mattias @ mvps.org ... Please reply only to the newsgroup. ...
    (microsoft.public.dotnet.framework.interop)