Re: Interop Marshalling Overhead - Newbie qn
- From: "steve" <steve@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 04:09:01 -0700
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.
>
>
>
.
- Follow-Ups:
- Re: Interop Marshalling Overhead - Newbie qn
- From: Willy Denoyette [MVP]
- Re: Interop Marshalling Overhead - Newbie qn
- References:
- Interop Marshalling Overhead - Newbie qn
- From: steve
- Re: Interop Marshalling Overhead - Newbie qn
- From: Willy Denoyette [MVP]
- Interop Marshalling Overhead - Newbie qn
- Prev by Date: Re: I think C# is forcing us to write more (redundant) code
- Next by Date: Re: compound interest calculation
- Previous by thread: Re: Interop Marshalling Overhead - Newbie qn
- Next by thread: Re: Interop Marshalling Overhead - Newbie qn
- Index(es):
Relevant Pages
|