MAINSAIL Structure Blaster User's Guide, Chapter 5

previous   next   top   complete contents   complete index   framed top   this page unframed


5. Structure Blaster Examples

Suppose that the POINTER p is the root of a structure that is to be stored in the data file f starting at the beginning of the file (page zero), and that f has previously been opened for random input and output. The following shows the simplest way to write the structure out and read it in again:

POINTER(dataFile)   f;
POINTER(...)        p;
...
$structureWrite(f,p);
...
p := $structureRead(f);

To avoid the extra page read required by $structureRead to get the size of the image, do as follows:

LONG INTEGER numPages;
...
numPages := $structureWrite(f,p);
...
p := $structureRead(f,0L,numPages);

To get the size of the image, then write it out, do as follows, where findStartPage is a user PROCEDURE that finds a big enough hole in f for the image:

LONG INTEGER        startPage,numPages;
POINTER($strucInfostrucInfo;
...
strucInfo := $structureSetup(p);
startPage := findStartPage(f,strucInfo.$totalPagesOrSize);
numPages := $structureWrite(f,p,startPage,strucInfo);
...
p := $structureRead(f,startPage,numPages);

previous   next   top   complete contents   complete index   framed top   this page unframed

MAINSAIL Structure Blaster User's Guide, Chapter 5