Is it better to use a database in memory (like SQLite) than store everything in a HashMap or other data structures?

I need to have very quick access to a large map - several million entries. Should I use the SQLite database in memory to save this map, and not just have this HashMap in memory?

+3
source share
4 answers

Depends on the services you require from your data structure. Do you only need to get the values ​​from the map? or do you need to perform a complex query or sort?

there is nothing magical about the internal structure of a database to make it arbitrary faster than a simple data structure. The database has more options to manipulate large data sets, which are likely to cost in processor memory and memory. if you need only a dictionary, as functionality, go with a map, for something more complex, consider a database

+5
source

It depends, but if your data model is simple enough to fit into the map, and you do not need to save data between runs of your program, then the database in memory is likely to be redundant. Databases are designed for more complex data models, secure concurrent access and updates using transactions, complex queries, restrictions, etc.

, , , . , java.util.collections, Google, Java . java.util.concurrent, ConcurrentHashMap, .

, . HashMap, .

, - , . , , .

+2

, , -, .

0

In addition to the wonderful comments of Alon and Jim, I would suggest trying both approaches and comparing performance. Besides being fun (admittedly defiant), this test will force you to encapsulate the data structure correctly, so that only the basic functionality will be revealed.

0
source

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


All Articles