- Home /
Performance between C# and C++ dll
My game is heavily depending on a C++ dll. C# and C++ functions call each other more than 100 times per frame. Unity profiler shows that it costs much time in MonoBehaviour.Update, but no any further details. And I didn't find any performance problem in C++ side.
How to know is there any performance problem between C# <-> C++ ? (Marshaling, Memory Boundaries, etc.) Or give me some advise, thank you!
BTW. I have read this page so I already have basic understanding of interoperating with native libraries: http://www.mono-project.com/docs/advanced/pinvoke/
Have you actually created a deep profile?
I doubt that the marshalling is the bottleneck. Just in case you didn't know, the Unity engine itself is written in C++. Almost all methods and properties of the Unity API are extern calls. For example Transform.position, Quaternion.AngleAxis, Vector3.RotateTowards, $$anonymous$$esh.vertices, GetComponent, FindObjectOfType, ....
Also almost all callbacks you get in your scripts are invoked from native code as well (Update, FixedUpdate, OnTriggerEnter, ....). It's possible that Unity has some sort of "shortcut" since they have direct access to the $$anonymous$$ono environment.
Check your deep profile and report back(maybe with a screenshot of the profiler).
Your answer
Follow this Question
Related Questions
Native Plugin works in editor but not in build 0 Answers
Unity iOS - "Assertion at reflection.c:6869" only in Development Build 0 Answers
Texture2D manipulation in c++ dll Plugin 0 Answers
cant add script component, because the script class cannot be found 0 Answers
C++ native plugin Failed with error '%1 is not a valid Win32 application 0 Answers