Download ALisp v2 User's Guide
Transcript
9. The Storage Manager
ALisp is integrated with a storage management subsystem callable from C. The storage manager is responsible for
allocation and deallocation of physical objects inside the database image. The C implementor has the choice of
allocating data persistently inside the database image by using a set of primitives provided by the storage manager.
Alternatively data can be allocated transiently by using the usual C routines malloc, etc. Persistency in this case
means that data allocated in the database image can be saved on disk and later restored. Persistent data is stored on
disk when the user issues the AmosQL statement save or call Lisp’s ROLLOUT function. The image is restored
when restarting the system with the image file as command line argument. By contrast, transient data disappears
when the system is exited. The C/C++ programmer can define own persistent data structures by using a set of
storage manager primitives.
Another important service of the storage manager is to provide a garbage collection subsystem that automatically
deallocates persistent memory no longer in use in the database.
The storage manager is actually independent of the ALisp interpreter. Its description is in this document as
knowledge of the storage manager is needed for defining external Lisp function.
9.1.
Handles
All access to physical objects is made through handles which are indirect identifiers for physical data records in C.
The representation of handles is currently unsigned integers. In order to make the application code both fast an
independent on the internal representation of handles, the handles are always manipulated through a set of C macros
and utility functions. The interface is furthermore connected to an automatic garbage collector so that data no longer
used is reclaimed when using those macros/functions. The interface between the storage manager is defined by the
header file storage.h.
Handles to persistent objects must be declared of C type oidtype and must always be initialized to the global C
constant nil. oidtype and nil are defined in storage.h. For example:
oidtype myhandle = nil;
This equivalent to the C macro dcloid:
dcloid(myhandle);
9.2.
Physical Objects
With every handle there is an associated C structure, the physical object, stored in the database image and holding
the value of the handle. The physical data objects are C structures containing the data to be stored persistently
together with a physical type identifier identifying the type of the object. The layout of the physical data object
depends on the datatype. However, the first two bytes of a physical object are always reserved for the system; the
succeeding bytes are used for storing the data. Every persistent data item must be represented as physical objects,
including literals such as integers and strings. For example, integers are represented by this structure:
struct integercelltype
{
objtags tags;
short int filler;
54