Search code examples
c#.netoptimizationclrc++-cli

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.


Solution

  • 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