Re: Interop Marshalling Overhead - Newbie qn
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Mon, 29 Aug 2005 12:34:07 +0200
"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: steve
- Re: Interop Marshalling Overhead - Newbie qn
- From: steve
- Re: Interop Marshalling Overhead - Newbie qn
- References:
- Interop Marshalling Overhead - Newbie qn
- From: steve
- Interop Marshalling Overhead - Newbie qn
- Prev by Date: Re: Datatable position
- Next by Date: RE: datagridview control easy filtering ?
- Previous by thread: Interop Marshalling Overhead - Newbie qn
- Next by thread: Re: Interop Marshalling Overhead - Newbie qn
- Index(es):
Relevant Pages
|
Loading