List with large number of items, excessive memory consumption

1

On my system I have a List<object> , while using the system I'm adding items in it until I get to a certain point where the system starts to slow down. My system may add up to forty thousand items in this list, I have never gotten to that point because it crashes before.

What could be done in this situation?

Note: I would not like to have to use a DB

    
asked by anonymous 07.02.2016 / 03:13

2 answers

2

If you know that it adds up to 40,000 items, it's a good idea to put a limit on that list, so you have a performance gain described

  

Every time you add an element to the list, and if the list is   with its memory allocation full, a new memory block is   used at twice the current size, and copies everything to this   block (performance drop) and continues adding new elements   until the list is full and the process repeats itself.

Then use:

List<object> lista = new List<object>(40000);

ANOTHER POSSIBLE PROBLEM:

If it is possible, instantiate the list with type defined, not "object", but I do not know if it has some performance gain.     

08.02.2016 / 02:10
0

Dude If you do not want to Use a DB You can try an approach like serialize your list in small blocks in Xml or Stream format, and store it on disk in an organized way by creating a search and maintenance system for that data. Or use a local sqlite-type bank that's just what it's going to do. Because anyway if an object of your use 20kb of memory multiplied by the total of the list is what it will consume and will not go out of memory because you keep it in use.

    
16.02.2016 / 13:53