It is a simple sample.
CodeDLL.cpp File:
extern "C" {
__declspec(dllexport) int __cdecl SimulateGameDLL (int a, int b) {
return a*b; // Calculation in native code
}
}
GameSharp.cs File:
static class GameSharp
{
public static class UnsafeNativeMethods
{
const string _dllLocation = "CoreDLL.dll";
[DllImport(_dllLocation)]
public static extern int SimulateGameDLL(int a, int b);
}
}
or
static class GameSharp
{
public static class GameSharpClass
{
public static int SimulateGameDLL(int a, int b) {
return a*b; //Calculation in managed code
}
}
}
The first one : I have a dll file that written in c++ native code and i try to call function in it in the managed code.(wrapper)
In the second one i have convert it to Managed Code.
My Code is not as simple as this.Which One is better Convert My c++ native code to Managed Or Call it form Managed Code.
Which one is faster? Why?
If this is not clear, please tell me i will discuss it more.don’t vote it to close before tell me. 🙂 thanks
I believe when it comes to performance in .NET there isn’t a noticeable difference between managed and unmanaged code.
I would convert your unmanaged code to managed if its all running on .NET anyway.
I just think you shouldn’t be worried about a performance bottleneck at this level. If your doing game development, you should be worried about performance when it comes to networking and graphics (use shaders).
EDIT:
http://msdn.microsoft.com/en-us/library/bb677124.aspx
“Maximum speed of execution. The managed layer adds around 10% overhead to the program.” (for windows mobile)