Next: , Previous: The fromRecord Method, Up: General Class Issues



5.1.5 toRecord, fromRecord, and exports

The toRecord method uses a feature called exports, which is a list of 2-tuples of the format Name#Type, where both Name and Type are atoms. The former is the attribute name to be saved, and the latter is the type of the attribute. Note that these types are specific to MOZ, and not Oz itself. The Type information is used to determine when special processing is needed to be able to safely save an attribute to disk. For example, toRecord uses the Type field to look for object references, which need special processing.

It is very important that the export list contain only the names of attributes that contain non-stateful data, or else the save will fail. Stateful data is data that is specific to a particular invocation of a running program, such as open file handles. Oz programmers also refer to stateful data as 'resources'.

Simple records, atoms, Oz names, and procedures are all safe.

Threads, file handles, and any other value that isn't guaranteed to be persistent, are all unsafe to save. Any attribute that stores this form of data either must not be named in the export list, or there must be special code in toRecord to deal with that Type, such as there is for the type called objectRef, which is for references to objects.

There is also an analogous featExports list for saving the value of features. Since features are write-once values, an object that has a featExports list should only have fromRecord called on it once. Any subsequent calls once the features have been initialized will fail.