Jump to content
  • Advertisement
Sign in to follow this  
Ned_K

[.net] Question about managed vs. unmanaged code

This topic is 4631 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

So, let's say I'm writing my project primarily in C# but I am going to use some native C or C++ for a few performance reasons. How is this unmanaged code really handled relative to the MSIL of the managed code, the JIT compiler and garbage collection? Also, are there any resources net or bookwise that address this specific issue in detail?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Ned_K
So, let's say I'm writing my project primarily in C# but I am going to use some native C or C++ for a few performance reasons. How is this unmanaged code really handled relative to the MSIL of the managed code, the JIT compiler and garbage collection? Also, are there any resources net or bookwise that address this specific issue in detail?

Taking it a line at a time:

I'd question the statement "for a few performance reasons". Unless you have two different versions and have measured exactly why one is much faster, you are just guessing and usually wrong.

Unmanaged code is able to use pointers and directly manage memory. The actual code will be handled differently based on the security settings and policies. It will make no significant difference with the JIT compiler. Garbage collection is also pretty much unchanged, you just need to be careful with properly freeing memory of your unmanaged code.

There are lots of books, but you might not need them if you are already comfortable with C++ windows programming.

One easy option is to used managed C++. If you are comfortable with the language already then you should be able to pick up the differences from MSDN and compiler warnings. Otherwise you might want to go browse the bookstore.

Another easy option is to use the C++ to generate a DLL and then use P/Invoke from the C# code.

If you're going the other way, make the C# code into a DLL and call it from the C++ code.

frob.

Share this post


Link to post
Share on other sites
I just ran a benchmark comparison against Native C++ and C# (.Net 2.0) yesterday.

While the diffence is noticable on .Net 1.0, I got almost identical results on the new version of .Net. Pretty amazing if you ask me.

The total operations (math, IO, etc, etc) took about 42 seconds on c++ and about 43 on C#.

The difference used to be about 10 seconds.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!