I'm working on 'database' program where I store objects in one file.
I want to read objects using mmap() function.
The storage is document-oriented database, where objects are formed into a tree.
The object struct (it has a size of 64 bytes) looks like this:
struct Entity {
section_off key_ptr;
size_t key_size;
section_off val_ptr;
size_t val_size;
enum value_type val_type;
file_off ancestor_ptr;
file_off child_ptr;
file_off sibling_ptr; // ptr to next child of the same ancestor
};
I store these objects in the sections into which the file is divided. Each section has a size of 8 Kbytes and begins with section_header struct:
struct section_header {
size_t free_space;
section_off first_free_cell;
section_off last_free_cell;
file_off section_addr;
};
So the question is:
What size part of the file do I need to map in order to go through all objects in my file? Should it be the size of a single section, multiple sections or the entire file? The file size can be unlimited.
I need to go through not only all the objects in the file, but also get some exact objects by it's address. So I should already have a function, that would map a certain object from a file or the entire section with this object. Therefore, I don't know if I need to implement a function, that would map multiple sections to go through the entire file faster.