The Performance of Arrays - Chris Burrows - 2 views
blogs.msdn.com/...the-performance-of-arrays.aspx
Development .Net Arrays Covariant Performance Reference
shared by Joel Bennett on 20 Jul 10
- Cached
-
arrays of reference types are covariant in their element type, but not safely
-
where did that exception come from? It came from the runtime, which was in a unique position to know what the real type of the array object was, and the real type of the element. It needed to determine if the assignment was allowable and throw if not. Now if you think about this for a minute, you can see that it’s going to have to perform that check for every assignment to an array element
- ...3 more annotations...
-
So if I want to have an array of reference types, but get the runtime to treat it like an array of value types, what have I got to do? Just wrap the reference type in a value type
-
So I got rid of that check, right? But I added the initialization of a value type. Did I win or lose? Let’s do some timing to figure it out.
-
when I build Debug binaries, the Reference<T> trick makes my example about three times SLOWER.