Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance of Calling Unmanaged .dll from C#

How long is the typical overhead added by calling a .dll written in C++ from a C# application using the following syntax?

[DllImport("abc.dll", EntryPoint = "xcFoo", CallingConvention = CallingConvention.Cdecl)]
public extern static Result Foo(out IntPtr session,
                [MarshalAs(UnmanagedType.FunctionPtr)]ObjectCallback callback, 
                UInt64 turnKey,
                string serverAddress, 
                string userId, 
                string password);

Is there a more efficient way to do it?

like image 622
Michael Covelli Avatar asked Mar 03 '10 22:03

Michael Covelli


2 Answers

Check out this article on how to improve interop performance. What to do and what best to avoid.

http://msdn.microsoft.com/en-us/library/ms998551.aspx

like image 54
Fadrian Sudaman Avatar answered Sep 18 '22 14:09

Fadrian Sudaman


Are you talking about the overhead of invoking the native method? If so, I dont think it is significant at all, as there are a lot of such calls in the .NET framework class libraries.

Now, whether the overhead is significant for your scenario can only be answered by doing performance measurements, and comparing them against what you expect.

like image 44
feroze Avatar answered Sep 20 '22 14:09

feroze