The Chunk class (See Figure 3.18) serves as the header of every allocation block in the Arena storage file. The class in invisible from the user.
The object size of the class is 16 bytes, but only 8 bytes are used when the chunk is in use. The unused part of the Chunk object is occupied by the first 8 bytes of the persistent object.
The member variable prevSize contains the size of the previous chunk and serves as the link to it. The member variable size contains the size of the chunk and two flags in its LSBs. Since all the chunks are aligned to the 16 byte boundaries, the 4 LSBs of the size can be used for other purposes.
One flag in the variable size indicates whether the previous chunk is in use or not. The other flag indicates whether the chunk is dummy or not. There are the accessors for manipulating these flags - isPrevInUse(), setPrevInUse(), clearPrevInUse(), isDummy(), setDummy(), and clearDummy(). The dummy flag is not fully implemented in the current version of the persistent storage.
The accessors for the variables size and prevSize are getSize(), setSize(), getPrevSize(), and setPrevSize(). They do not affect the two flags in the LSBs.
The remaining member variables backward and forward are used only when the chunk is not in use, and contain the offsets of the previous and next free chunks, respectively. These variables constitute the doubly-linked list of the free chunks in the Arena storage file. These variables have no accessors and are accessed directly by the Arena operations, although there are no firm reasons for the missing of the accessors.
The constructor for the class takes all the variables and flags as the parameters, some of which are omittable.
The operation getMemBlock() is used at the last part of the pointer conversion to the reference pointer. Pointers to the Chunk objects are internally used for all the operations in the persistent storage, because the persistent storage does not care the contents of the persistent objects but the arrangements of the chunks in the persistent storage. Conversely, the user does not care the internal arrangements but only focuses on the reference pointers to the persistent objects.
Therefore, the conversions to the valid reference pointers are performed just before the pointers are handed to the user. The operation returns the pointer to the member variable backward, which is casted to the PointerType when returned. The pointer is the starting address of the mapped persistent object. (The PointerType is just the defined type for void *.)