In-memory databases

Default featured post

Sometimes in programming need to hold many objects and classes into memory, however, this will cause shortage of heap memory or memory leakage eventually. In order to avoid this bad practice and also not using hard disk to save the data due to its low access speed, you can use in-memory databases.

There are variety of in-memory databases are available on the internet and also some well known relational databases have in-memory features which allow you to create database, table in-memory or remote server memory which I personally think it is awesome feature.

Another usage of in-memory database can be for sorting, comparison and traversing the entire data quickly. For instance, in the field of Recommender System, there is a technique called memory-based collaborative filtering in which, the entire user-item database (a.k.a matrix) is held in-memory since for each user, user time, the system should scan the entire db to find appropriate peer users and items for recommendations. Now, assume without in-memory database a researcher who decides to implement this method for any purposes would have really tough time and more precisely nightmare since he/she should use objects, vectors, lists, tree map or any other data structure to hold the data in-memory which at the end would most probably come across with memory leakage issue.

One of the best in-memory or in disk database is SQLite. SQLite supports in-memory database as well with not much effort. For example, if you have developed a program with SQLite which uses in disk database with changing one line you can change it to in-memory database. You just need to change like the following (in Java).

Find the following line,

connection = DriverManager.getConnection("jdbc:sqlite:test.db");

Change to :

connection = DriverManager.getConnection("jdbc:sqlite::memory:");

For getting list of in-memory databases check this link.