Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why are interop calls (P/Invoke and COM interop) slower compared to a managed instance call?

0
Posted

Why are interop calls (P/Invoke and COM interop) slower compared to a managed instance call?

0

P/Invoke (Platform Invoke) and COM interop calls in .NET Compact Framework are significantly (~5-6 times) slower than regular managed calls. Although the overall performance penalty largely depends on types marshaled between managed and native code (marshalling overhead), there is also a common overhead, primarily due to some internal work preceding and following every platform call. This work is needed to notify the runtime that the call must be GC (Garbage Collector) preemptable to avoid the GC from being blocked until the interop call is completed. This is why it’s important to maximize the amount of work performed inside each interop call and avoid multiple frequent invocations.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.