Connecting Tech Pros Worldwide Help | Site Map

C++ interop & P/Invoke

  #1  
Old November 19th, 2008, 08:55 PM
=?Utf-8?B?UmFq?=
Guest
 
Posts: n/a
I want to understand why C++ interop has better performance than P/Invoke.
Can someone explain in detail.

Thanks
  #2  
Old November 21st, 2008, 07:35 PM
Ben Voigt [C++ MVP]
Guest
 
Posts: n/a

re: C++ interop & P/Invoke




"Raj" <Raj@discussions.microsoft.comwrote in message
news:DED890A2-F3C6-48AF-90C1-84468DB47FE9@microsoft.com...
Quote:
I want to understand why C++ interop has better performance than P/Invoke.
Can someone explain in detail.
Because P/Invoke does a lot of extra stuff (pinning, blitting, error
checking, etc.)

C++ interop just pushes the parameters on the stack and calls the function.
Ok, some things still need to be converted or pinned, but with C++ interop
you can convert once and call a whole bunch of APIs, with P/Invoke EVERY
parameter passed by address gets pinned and unpinned on EVERY call, copied
and copied back, etc. Or C++ interop can avoid the pinning problem entirely
by creating POD structures on the native heap where they never move around.

Plus the C++/CLI compiler inherited a lot of very complicated optimization
logic that .NET hasn't duplicated yet.
Quote:
>
Thanks
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ interop & reliability contracts Can answers 0 February 16th, 2007 10:25 AM
Confusion: Threading & COM Interop Z D answers 8 November 21st, 2005 05:31 AM
Confusion: Threading & COM Interop Z D answers 8 November 16th, 2005 02:22 PM
Data marshaling between unmanaged C++ & C# Vadym Stetsyak answers 4 November 13th, 2005 09:18 PM