I
I
iamserge2019-08-29 14:53:15
Arrays
iamserge, 2019-08-29 14:53:15

C# - how to choose an in-memory data store?

There was a case, the need forced me to turn to the DBMS , but I avoided this quite simply. It was possible to split the data into fragments of 1 - 20 Mb, so that requests do not capture more than one such file. That is, it was possible to separate everything without any damage, from which I was able to abandon the DBMS in principle, returned to XML and everything is fine ...
But still, the problem overtook me, it became necessary to store data in an "array". I write like this because I have been using them in PHP for 15 years and did not know grief. Just because there was nothing plainly, the question did not stand. However, nothing lasts forever... Therefore, now in C# you need to do something like this:


<?php
$E = array(
array(double, DateTime, double, string, int),
array(double, DateTime, double, string, int),
array(double, DateTime, double, string, int),
array(double , DateTime, double, string, int),
array(double, DateTime, double, string, int)
}
?>

I intentionally indicated data types instead of an example, so that it would be clearer and no longer tied to PHP. In general, there are many tips on the topic, different experiences. Now I just tried dictionaries. But there was a problem with the keys, it turned out that I can’t choose anything as a key, DateTime sometimes matches. But it was more of a temporary solution ...
So the question is, what about the data? At the same time, at the moment everything is stored in XML, it is the main format from which I want to send everything to memory and exploit it. Maybe it’s worth storing it differently ... Maybe this will give its advantages, I already thought to “learn” to store them binary (in the sense I never stored them, but I noticed that developers often do this, especially games, when the data is archimal and everything is packed into a dozen or two files).
But so far I don’t see a solution, I’m reading a little about everything, but I don’t see a solution on the surface, and I don’t know ... How to solve the problem? And here is the most important remark, I need to do a lot of operations with this data: count, compare, verify, etc. ... That is, everything seems to be one cycle, but there will be a lot of "activities", from which the painful question hung ...
Microsoft, for example, is not verbose :
Represents a collection of keys and values.

Here they say, and then look how it is there ... And how is it there then?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2019-08-29
@2ord

Essentially, a list of elements of a certain structure is required.
But if you need data persistence, then in my opinion the best solution would be a DBMS like SQLite. It will be both more economical in memory consumption and more scalable.

S
Sumor, 2019-08-29
@Sumor

It all depends on what is needed.
If you just need to serialize, then you need IEnumerable.
If you need to know in advance the number of elements, then you need an ICollection.
If you need work access by element indexes, then you need IList.
If work on keys is necessary, IDictionary is necessary.
If you need to bind/handle element changes, then you need an IBindingList or IObservableCollection.
These are the basic features that any class for storing elements will inherit. Further, if the method of storing elements or special access is important, choose or implement a class with the necessary interfaces and capabilities.
Base classes: array, List<T>
Queue<T> - queue
Stack<T> - stack
Dictionary<TK,TV> - a dictionary
ObservableCollection<T> - a collection with support for change events

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question