C++ interop & P/Invoke

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UmFq?=

    C++ interop & P/Invoke

    I want to understand why C++ interop has better performance than P/Invoke.
    Can someone explain in detail.

    Thanks
  • Ben Voigt [C++ MVP]

    #2
    Re: C++ interop & P/Invoke



    "Raj" <Raj@discussion s.microsoft.com wrote in message
    news:DED890A2-F3C6-48AF-90C1-84468DB47FE9@mi crosoft.com...
    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.
    >
    Thanks

    Comment

    Working...