The fundamental algorithm of mapping the persistent objects in the main memory is shown in the Figure 3.8. Most of the peripheral features are omitted from the diagram.
An instance of the PersistentPointer class has a pair of integers - arenaID and offset. When the PersistentStorage object is requested for the mapping of the persistent object pointed by the pointer, these integers serve as the clues to the mapping and the address conversion.
The PersistentStorage object has the table of the Arena objects. The Arena object with the arenaID is selected for the mapping. The Arena class controls one storage file for the persistent objects. The selected Arena object then searches for the appropriate Window object for the mapping in the table of the mapped Windows. If there are no appropriate Windows in the table, a new Window is created for the mapping.
The selected or created Window object then searches for the appropriate PersistentOffset object in the objectTable, whose elements correspond to the persistent objects in the Window. The offset in the PersistentPointer object is used for searching the object in the table. If the offset points to the valid Chunk object in the Window, there should be an element with the offset in the table. The selected PersistentOffset object and the Chunk object together contain the information on the persistent object at the offset such as whether the object is grabbed or not, how many pointers are read-only-grabbing the object, whether the Chunk is in use or not.
When all the requirements for the mapping are fulfilled, the reference pointer for the persistent object is calculated from the address of the Chunk object in the main memory, and finally handed to the user.
A Chunk object is placed at the top of every memory block in the Arena storage file and appears in the main memory when the Window object which contains the Chunk object is created.
Each Chunk is doubly linked with the immediate two Chunks by containing the size of the memory block and the size of the previous memory block. Such memory blocks are just called chunks. Free chunks have additional information on the previous and the next free chunks in the Arena, that is, they are doubly linked with the immediate free chunks by the offsets to them.
It must be observed that not all Windows which contain the Chunk object at the requested offset are suitable for the mapping. The reason is that the whole chunk may not be contained in the Window. Such chunk is fragmented and cannot be used for the reference of the persistent object.