MAINSAIL Language Manual, Section 47.21

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


47.21. setPos

Figure 47–25. setPos
BOOLEAN
PROCEDURE   setPos      (POINTER(filef;
                         
OPTIONAL LONG INTEGER n;
                         
OPTIONAL BITS ctrlBits);

setPos sets the position within a file opened for random access to n.

The units used for positioning are character units. The first position in a file is position 0L, the next position 1L, and so forth.

If the specified position n is greater than the end-of-file position or is negative, setPos returns FALSE. In this case it also gives an error message unless the errorOK bit is set in ctrlBits. errorOK is the only valid ctrlBits bit.

The following shows how an ARRAY that is too large for memory may be maintained as a random access file:

simulate an ARRAY on disk

DEFINE
   
liIntegerSize(f)  =     [cvli($ioSize(f,integerCode))],
   
hugeArySize(f)    =     [20000001L * liIntegerSize(f)];

simulate INTEGER ARRAY(0 TO hugeArySize - 1) hugeAry
POINTER(dataFilehugeAry;
open(hugeAry,"hugeAry",create!random!alterOK);

simulate hugeAry[li] := n
setPos(hugeAry,li * liIntegerSize(hugeAry));
write(hugeAry,n);

simulate n := hugeAry[li]
setPos(hugeAry,li * liIntegerSize(hugeAry));
read(hugeAry,n);

Specifying a constant numeric value other than 0L for a data file position is machine-dependent. For portability, all file positions in data files should be specified as multiples of sizes of the MAINSAIL data types using $ioSize. For example, to position to the second INTEGER in a data file, use setPos(f,cvli($ioSize(f,integerCode))).


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

MAINSAIL Language Manual, Section 47.21