Monday, November 24, 2003 10:28 AM
richard
Fast Heterogenous Array
Some interesting discussion about accessing multiple (but known) types from a single array on Google Groups. My solution involved using StructLayout to create a union-ed struct that contained the types you wanted to access being up to 40% faster than casting/unboxing value types. The download of my code can be found here
Oh and btw, this syntax:
(obj[i] as MyType);
if quite a bit faster than this:
(MyType)obj[i];
Due to the differing IL they product, of course. The former produces a castclass IL instruction, while the latter is simply an isinst which does affect the object on the evaluation stack, but seems to not be as expensive as castclass.