Overhead - C ++ function call from C #

I call two C ++ functions from C #. Performing this at an iteration of about 1 million calls, I see an overhead of about 30%.

C ++ function:

EXTERN_C void STDAPICALLTYPE FunctionA(UINT_PTR mathId)
{
    ...
    ...
}

In my c # dll assembly:

[DllImport("CPlusPlus.dll")]
    public static extern void FunctionA([In] IntPtr mathID);

Called from a function, as shown below:

 public static void HelpingFunction([In]UInt64 mathID)
    {
        FunctionA((IntPtr)mathID);
    }

This implementation method creates additional overhead when the HelpingFunction is called more than a million times.

Can someone give me other ideas to reduce overhead? What are other ways to call a C ++ function from a C # assembly?

+4
source share
1 answer

You can try adding SuppressUnmanagedCodeSecurityAttribute.

Allows managed code to call unmanaged code without going to the stack.

https://msdn.microsoft.com/en-us/library/system.security.suppressunmanagedcodesecurityattribute.aspx

p/invoke :

PInvoke 10 30 x86 . . . , int Int32.

https://msdn.microsoft.com/en-us/library/ms235282.aspx

+7

All Articles