Since I'm on collections, strongly typed arrays, versus List<T> for very large collections... I want a Decompose method...
Collections, are collection, are collections. NOT! Collections are arrays somewhere, at least in most cases. More often than not I find myself using an ArrayList (in V1/1.1) and then converting the said list to a strongly typed array for quickly running over the values. The conversion is fine for smaller arrays, but for larger arrays the conversion really sucks, and it takes up twice the memory. After all, don't you already have a collection back there somewhere?
Well, for ArrayList it makes sense they made us do all the copying since the backing array was of type System.Object. But now we have List<T>. The array backing that is already strongly typed and ready to go. Hell, shouldn't I be able to get a reference directly to the already built array for use? Sure it may have a couple of extra elements that I don't need, but it is up to me to handle the esoterics of indexing. What is currently available and what am I looking for?
There is already a CopyTo method that I could use. However, this is exactly what it says, a copy. There is also a ToArray, but that creates a copy of the array. You could say I should just use the indexer on List<T> since it is now strongly typed, however, get_Item() has a bunch of crappy range checking logic that is going to slow me down just that little bit. What I'm looking for is a Decompose method. Reset the internal state of the collection to a new array, and return me the reference to the old array. Of course your ReadOnlyList would throw an exception on this, as it should, but your normal List<T> should run just fine. After all, the user could always just call Clear, so it isn't like the internal array you are using is sacrosant in any way to warrant the protection of it.
Any takers? Anyone think that direct access to the underlying array without copying for things like Stack<T>, Queue<T>, and List<T> would help out any?