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.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.