I have some C# code that requires extensive binary manipulation, so I wrote an unmanaged C++ method to replace one of the C# methods. To my shock, is was 10 X slower. I ran a profile, and discovered the slowness comes from the overhead of calling the external method, not the method itself.
So I thought that if I write the method in managed C++, I will loose the overhead of the call, but still have the speed of C++. First, is this assumption valid?
Here is my unmanaged C++ code:
#include "stdafx.h";
unsigned __int32 _stdcall LSB_i32(unsigned __int32 x)
{
DWORD result;
_BitScanForward(&result, x);
return (unsigned __int32)result;
}
Here is my C# code:
public static partial class Binary
{
[DllImport(@"CPP.dll")]
public static extern int LSB_i32(int value);
}
Am I doing anything wrong here?
How do I translate the above to managed C++? I did some browsing on this, but because I am unfamiliar with managed C++, I didn't get far.