Sign in to follow this  

[.net] Optimising C# code

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

Well... i'm not so good at C#. I have wrote a planet class, which implements sponeill's algorithm (found on gamasutra.com). It works, this isn't the problem. The problem is that my triangle splitting and merging function are awfully slow (my profiler indicate that most of the program time is used for splitting/merging the triangles from the planet). The algorithm has been converted from C++ (which was using lots of pointers; triangles have pointers to neighbors, and so on). When I did the conversion, I translated all to objects references (now, instead of neighbors array being pointers to objects, this is an array of objects references). I also use a lot of pure getter/setters in my splitting/merging functions, and was wondering: - does the use of pointers speed up considerably things? - does the overhead use of getter/setters be neglectible (tested, seems to)? - do you know other well known optimisations that I should be cared of? I'm not currently near my computer, but i'll post some profiling results to show where the program use most of it's time.

Share this post


Link to post
Share on other sites
The most important thing to think about as far as performance goes with .Net stuff is reuse where possible. So instead of allocating and deallocating copies of arrays or whatever, try and reuse them.

Does your profiler indicate that you are allocating loads of memory that's not being collected straight away?

Share this post


Link to post
Share on other sites
Hi Paulecoyote,

Thanks for your answer. Like you suspected, I have in my faulty code some allocation/deallocation of objects (an array and 4-5 objects in my Split() function, 2-3 objects in my Merge() function). I'll try to profile those allocation to see how much time it takes to do them.

It would also explain why O'Neill was using static function variables in his code :D (mem alloc FTL /o\).

Share this post


Link to post
Share on other sites

This topic is 4222 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this