Visual studio feeds

All Visual Studio blogs in one place


Enter your email address:

Delivered by FeedBurner

Increase your website traffic with



Anti-spam: How many eyes has a typical person?

Follow us on FB


Memory Consumption: List<T> vs IndexedList<T>

AddThis Social Bookmark Button
When you want to store millions of strings in a list you will notice in your memory profiler that the biggest memory consumers strings and lists are. If you e.g read many lines from a file with repetitive data inside it you can use a reference cache to consume the actual memory for the same string only once. The CLR offers String.Intern to do exactly that but the string reference cache is cross AppDomain static which is mostly never a good choice. Where could you use this? If you parse log files where many rows of data are often
the same like type name, method name, … it can save you a lot of memory. If you use a List and intern all of your read strings you still store references in your list which will make the object graph more complicated and GC cycles slower. Besides this a reference does cost you 4/8 bytes in 32/64 bit processes. A generic read only index based list to which you simply add your data can make a huge difference. I could read a 200 MB log file in 17s by using a List and it did drop to...(Read whole news on source site)

Home : Blog List : Alois Kraus : Memory Consumption: List<T> vs IndexedList<T>