Two Freespace Systems

db4o comes with two freespace systems, one holds all freespace information in RAM, the other uses the internal indexing architecture. You can configure db4o to use either of the two by calling

.NET: Db4oFactory.Configure().Freespace().UseRamSystem()

or

.NET: Db4oFactory.Configure().Freespace().UseIndexSystem()

This call should be made before you open the database for the first time

By default db4o uses RAM freespace management system. The information about free slots is loaded into memory on opening a database file and discarded on closing it. This system is quite fast, but it has its downside:

  1. Higher RAM usage during operation.
  2. Loss of freespace upon abnormal termination. That is done for security reasons and freespace can be reclaimed using defragmentation.

RAM-based freespace management is a good performance solution, but it can be insufficient for the systems with limited RAM resources and high probability of abnormal system termination (power failure on mobile devices).

In order to meet the requirements of such environments new index-based freespace management system was built. It solves the problems of RAM-based system:

  1. RAM usage is kept at the minimum, as the system always operates from file.
  2. No freespace is lost on abnormal system termination (database file won't grow unnecessarily).

How it works?:

  • The system uses existing index functionality to keep information about available freespace
  • Index operates against the file, not against memory
  • For every new write to the database file the system tries to find a freed slot, which is at least the size needed or greater, traversing freespace index
  • When an object is updated or deleted, its 'old' slot is added to the freespace index
  • This index system is transactional (no information is lost upon abnormal system termination)
  • It stores diffs in a tree in RAM (index add/remove) together with nodes that represent parts or the whole index, as it exists in the file.

Index-based freespace system can show poorer performance compared to RAM-based system, as file access for index traversal it comparatively slow.

However, index-based freespace system can be a reasonable solution for mobile devices, where file access is not much slower than RAM-access, and ACID transactions together with low memory consumption are most valuable factors.