M
Mark
I've been reading many of the articles on why C# doesn't have true readonly
arrays and I was doing a little time testing.
I found the ReadOnlyCollection<T> = Array.AsReadOnly<T>(T[]) construct but
when I ran some time tests, I was appalled to see that simple read access was
between 8x and 9x slower than just using a regular array (for type char
anyway).
I threw together a simple wrapper:
public class RArray<T>
{
private T[] holdme;
public RArray(T[] init)
{
holdme = (T[])init.Clone();
}
public T this[int i]
{
get { return holdme; }
set { throw new InvalidOperationException("No way"); }
}
}
And the same timing test had my wrapper at around 75% slower.
Using Reflector, I looked at ReadOnlyCollection<T>'s get method and saw it
was doing essentially the same thing my wrapper was, so I couldn't explain
why ReadOnlyCollection<T> was just so much slower.
Any ideas?
Thanks
Mark
arrays and I was doing a little time testing.
I found the ReadOnlyCollection<T> = Array.AsReadOnly<T>(T[]) construct but
when I ran some time tests, I was appalled to see that simple read access was
between 8x and 9x slower than just using a regular array (for type char
anyway).
I threw together a simple wrapper:
public class RArray<T>
{
private T[] holdme;
public RArray(T[] init)
{
holdme = (T[])init.Clone();
}
public T this[int i]
{
get { return holdme; }
set { throw new InvalidOperationException("No way"); }
}
}
And the same timing test had my wrapper at around 75% slower.
Using Reflector, I looked at ReadOnlyCollection<T>'s get method and saw it
was doing essentially the same thing my wrapper was, so I couldn't explain
why ReadOnlyCollection<T> was just so much slower.
Any ideas?
Thanks
Mark