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.
You can initialize a List with a capacity if you have a rough estimate of the maximum size. As far as I know, that will avoid the heavy garbage collection happening (with the old smaller arrays), which might also avoid the memory fragmentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With