[.net] Optimising C# code

Started by
1 comment, last by PERECil 17 years, 11 months ago
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.
Advertisement
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?
Anything posted is personal opinion which does not in anyway reflect or represent my employer. Any code and opinion is expressed “as is” and used at your own risk – it does not constitute a legal relationship of any kind.
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\).

This topic is closed to new replies.

Advertisement