How to store large amounts of data in memory in the form of Windows C #

I currently store about a million rows in a DataTable, it takes about 600 MB of RAM.

So, when you run the application, it stores 1,000,000 rows in a DataTable and displays it on a GridView. When you close the application, this will obviously clear the memory.

I would like to provide the user with this option, in other words, when the user tries to close the form, they will ask him if he wants to clear the memory or not.

The reason for this is that you do not have to wait until the data is read into Datatable every time it launches the application.

.... I am new to C #, so I apologize if this is the relevant question.

+4
source share
3 answers

You can only store anything in memory, if there is a working application / process in memory with this data - if your application is closed (and there is only one instance of your application open with this data in memory), then the memory will be released. If you want to keep it in memory, your options will be

  • Do not close the application, for example. just hide the window instead (usually a very bad idea that your users will not thank you)
  • Store this data in another separate process that works even when your application is missing, for example, a Windows service (maybe this is not what your users will thank you for if you are not really trying to develop a form of service, unlike Windows applications).

It would be much better to change the way your application works with large data sets, so that it does not need to store everything in memory, for example, if you display all this data in a large list view, and then use a virtual list so that only memory is loaded those lines that are currently displayed to the user. Then you can store your data either in an external database or in a semi-permanent file (for example, in a SQLite database).

Or just upload a dataset every time now.

+3
source

I suggest you store it in a file or database, and not in memory. You can request some data that you want to use at runtime. For example, 20 or 50 records at a time.

It doesn’t make sense if you immediately show 1M records in a datagrid, and I’m sure you won’t even look through them.

+3
source

Try compressing a specific area of ​​the data (the set of objects corresponds to the rows) and extract if necessary. See Compressing an Object in Dot Net

0
source

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


All Articles