The following is a sample code for the primitive operations. Error handlings are omitted from the sample for simplicity.
// Declarations
PersistentStorage *ps; // the persistent storage
PersistentPointer pp; // the persistent pointer
PersistentObject *obj; // the reference pointer
pp = ps->allocate(sizeof(PersistentObject)); // Allocate
// Grab and Instantiate
obj = new(pp.grab()) PersistentObject(parameters, ...);
obj->manipulate(parameters, ...); // Manipulate
pp.release(); // Release
obj = 0; // Invalidate the reference pointer
obj = pp.grabReadOnly(); // Read-only-Grab
obj->reference(parameters, ...); // Reference
pp.releaseReadOnly(); // Read-only-Release
obj = 0; // Invalidate the reference pointer
obj = pp.grab(); // Grab
obj->~PersistentObject(); // Destruct
ps->destroy(pp); // Destroy (also Release)
ps->synchronize(); // Synchronize
The persistent pointer and the reference pointer are declared at first. Each operation is almost self-explanatory. Comparison with the Figure 2.2 would be helpful.
An explanation should be needed for the destroying operation. The storage block must be grabbed when destroyed. Otherwise, any object would be destroyed arbitrarily.