When using P/Invoke, adding [SuppressUnmanagedCodeSecurity] can speed calls from managed code into unmanaged code in trusted scenarios.
Is there a way to accomplish the same thing in the reverse direction, to speed things up when I call from unmanaged code back into managed code? Profiling shows a much higher overhead going in that direction in our application.
I haven't found anything about suppressing code security, maybe because there's no such stack-walking checks calling from the unmanaged side, but how you marshal your types has an effect on performance. Here's a link showing different ways of marshaling strings, and the perf results:
Reverse P/Invoke Marshaling Performance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With