C# High performance programming

I have noticed a number of comparisons with C++ and C# for high performance systems , and the same mistakes are frequently made. I will go over a C# queue which is frequently used in high performance systems.

1. Any linked list system in C# will preform badly unless -

  • You manage your memory yourself via unsafe pointers OR
  • You recycle nodes ( which will still not offer great or C++ performance)

The reason for this should be obvious since any new to create a new record is FAR more expensive than enqueing and most locks.  Hence very high performance C# datastructures really need to be based on arrays or be unsafe .

2. Structs and Queues are very dangerous

structs can offer excellent performance especially when passed around via ref. however there are a number of issues..

You can pass in structs via ref and retrieve them via out. Note however if you use ,out a queue will reasign the space immediately and hence your data will get over written so this is prob a bad idea.

Also note when using ref with a struct it can have unintended consequences eg

AMethod( ref myStruct)

{

array[0] = mystruct;

}

is almost the same as the method without the ref , the ref will cause an additiona CIL loadobject and hence perform worse.

 

                              

Print | posted on Sunday, February 14, 2010 10:10 AM

Feedback

No comments posted yet.
Title  
Name
Email (never displayed)
Url
Comments   
Please add 4 and 5 and type the answer here: