Storing data in memory, what is a good way?

I have an items.xml file that loads into memory after running the application. Each items.xml element is "converted" to a type Item(which has only a few int and string properties), and then added to the list of elements. The list of items must contain thousands of instances Item.

Saving data in objects (class Itemin my example) in order? Is there any other way to store such data in memory?

+3
source share
5 answers

Think about how to use the functionality first. Secondly, worry about performance. Profile your application and see where it hurts in performance. It can never be in your config. If, however, you are experiencing performance problems in this area, try inventing keys for individual or subsets of elements. Thus, you can fill one or several dictionaries with keys and elements (or lists of elements), thereby reducing the access time to the element in question.

Remember that these search dictionaries are β€œcheap” because they only store links to your items, not to copies of objects.

+7
source

, , , . .

-, , , :

Dictionary<string, Item> lookup =
    list.ToDictionary(x => x.Code);

:

Item item = lookup["abc012"];

; , , ;

Dictionary<string,string> interner =
    new Dictionary<string,string>();
foreach(Item item in list) {
    string s, name = item.Name;
    if(interner.TryGetValue(name, out s))
        item.Name = s;
    else
        interner.Add(name, name);
}

+5

, , .

XML - , XDocument Linq to XML.

+1

, Item, , , , .

100 000 ( 1000), List . . , , , .

, , , - ( , ).

, () , , . . , .

0

? , . , , .

, :

  • ... ?
  • ... XML?
  • ... , - XML?
  • ... , , /?

- , . , . , ACID.

0
source

Source: https://habr.com/ru/post/1779740/


All Articles