List is a wrapper over array. While you add items to the list it creates bigger and bigger array undercover (and previous array is garbage collected). But if you treat large lists at some point you will get OutOfMemoryException even if there is free memory due to memory fragmentation. I am looking for an ICollection implementation which would work with set of arrays undercover similar to what MemoryTributary does.
Update.
I have found BigArray implementation here:
http://blogs.msdn.com/b/joshwil/archive/2005/08/10/450202.aspx.
While it tries to solve other problem (creating an array of >2GB size), it solves my problem too. But this implementation is not full and even does not compile. So if I don’t find any better, I will improve this one and use it.
I haven’t found any good implementation. So I have written my own ChunkyList. Generally ChunkyList is a List of arrays wrapper. Initially block has size of 1 but it is multiplied by two (when it reaches MaxBlockSize, a next block is created) every time you need to extend the current block (the behavior similar to the List).
Here is a generic ChunkyList:
And here are tests which prove this implementation works:
P. S. I have implemented only those IList methods which are used in my code. So you are welcome to improve this implementation.