Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set SuppressUnmanagedCodeSecurity for callbacks?

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.

like image 596
Dave Moore Avatar asked Oct 16 '25 15:10

Dave Moore


1 Answers

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

like image 159
Oliver Mellet Avatar answered Oct 18 '25 04:10

Oliver Mellet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!