Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory usage, SortedList vs List problem
    text
    copied!<p>I was using SortedList() in a class which stores about 15-100K data.</p> <p>Recently my requirements changed, data should not be stored as sorted any more so I switched to List().</p> <p>However in this case I noticed that List() consumes about 20%+ more memory.</p> <p><strong>9K items:</strong> </p> <ul> <li>SortedList: 105MB</li> <li>List: 125MB</li> </ul> <p><strong>15K items:</strong> </p> <ul> <li>SortedList: 115MB</li> <li>List: 140MB</li> </ul> <p>In the environment I develop, memory is quite crucial. Instead of List() what can I use to avoid this extra memory consumption and still have a non-sorted list?</p> <p><em>P.S. I do use a HashSet(Of String) to provide uniqueness check while using List(Of) to simulate SortedList.ContainsKey() although I don't think it can bring such memory overhead.</em></p> <p><em>P.S. 2: My app has got about 80 MB base memory allocation in the startup. So numbers should read as 105-80=25, 125-80 =45 and so on</em></p> <p><strong>RESULTS</strong></p> <p>Thanks for the all answers, final results are:</p> <ul> <li>You should set the correct capacity to save memory</li> <li>Hashset is very bad about memory, and consumes way more than expectations. This was the problem. Somehow SortedList() manages to use less memory for a similar functionality.</li> </ul> <p><strong>Some Bencmarks:</strong> 500 chars, 250000 insert</p> <p><strong>List(OF STring)(50000)</strong></p> <p>274 ms - 226 MB</p> <p><strong>SortedList(Of String, String)(50000)</strong></p> <p>34868 ms - 230 Mb</p> <p><strong>Hashset</strong></p> <p>420 ms - 232 MB</p> <p><strong>Dictionary(OF String, Object)</strong></p> <p>486 ms - 234 MB</p> <p>Although when I changed decreased count to 25, then:</p> <p><strong>Hashset</strong> for 600.000 iteration 300 Mb where <strong>List()</strong> is 286 Mb</p> <p>Also about Hashset memory usage: <a href="http://blog.mischel.com/2008/04/09/hashset-limitations/" rel="nofollow noreferrer">http://blog.mischel.com/2008/04/09/hashset-limitations/</a> Dictionary(Of string, object) was not much better either in my test.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload