Jump to content
  • Advertisement
Sign in to follow this  

[.net] Cost of using unmanaged wrappers in C#?

This topic is 4346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How much of a performance hit % is it to use a wrapper to access C++ functions/classes from C#? Context: I was thinking of using the OgreDotNet wrapper for Ogre3D, and just wanted to find out this small point. I know speed for small games is irrelevant, but I'd just like to know.

Share this post


Link to post
Share on other sites
Advertisement
Most of the cost is in marshalling/unmarshalling the data. For instance, strings must be made into a form that is usable in a C/C++ API. I don't think its possible to come up with a % in general, because it depends greatly upon how often you cross the boundary between managed and unmanaged code, and the kind/amount of data you have to marshal/unmarshal. But, my experience is that the performance hit is usually minor. It depends upon how efficient your wrappers are, but my guess is that the performance hit caused by the wrapper will be significantly less than the overall performance hit of using C# over C++, which many gauge at about 10%.

Share this post


Link to post
Share on other sites
While this isn't exactly the answer your looking for, it should be more or less close to the same thing. Axiom, the C# version of OGRE, runs at about the same speed as OGRE does. Some cases it was faster, some it was slower. And while Axiom was written in C#, it still has to access the unmanaged libraries for all of its 3D functionality.

I hope that helps :)

Share this post


Link to post
Share on other sites
make sure you add the following attribute to your .dll imports:

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport(...



This way, the runtime will not do a stack walk of (which is checking that no local memory has been corrupted in the unmanaged function). This assumes that you *know* that the unmanaged function is rock solid. Naturally it makes things much quicker, but has a certain risk.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!