Rem

1250 REM Use MOVESDATA to quickly and "randomly" initialize the 1260 REM arrays of test values, by copying parts of ROM. 1270 REM

1290 ZT=VARPTR(YYl(0,0,0)) : GOSUB 11 : Z T=VAR PTR(YVl(0,0,0)) : GOSUB 11

1310 ZT=VARPTR(WW#(0,0)) :GOSUB 11:ZT=VARPTR(WVt(0,0)):GOSUB 11 1320 ZR=FNZ1(XI,2): ZF=RND(12000-ZR)

1330 ZT=VARPTR(XX(0)):GOSUB 11:Z T=VAR PTR(XV(0)):GOSUB 11 1340 RETURN

GATHERSWRITE uses unformatted I/O to write a set of data to file ZOS. as specified by the contents of array ZA(ZZ,1). ZA(0,0) is the number of data sets (ZZ sets maximum). ZA(K,0) points to the start of the K data set. ZA(K.l) is the number of bytes in the K data set. GATHERSWRITE calls OPENSFILE and WRITSQWIK and changes variables ZK. ZI. ZF. ZN.

SCATTER$READ uses binary I/O to read in a set of data from file ZOS. distributing data as specified by array ZA(ZZ, 1). It Is the inverse of GATHERSWRITE. It calls OPENSFILE and READSQWIK and changes variables ZK, ZI. ZT. ZN.

OPENSFILE opens file ZOS for direct access. sets up I/O buffer ZO for a record size of 256 bytes, and puts the address of the I/O buffer in ZB. It changes variables ZI. ZB, ZB$.

SAVESRANGE saves a range of memory from ZF to (but not including) ZT to file ZO$. It calls OPENSFILE and WRITSQWIK and changes variable ZN.

LOADSRANGE loads a range of memory from ZF up to (but not including) ZT from file ZOS. It calls OPENSFILE and READSQWIK and changes variable ZN.

You must declare all simple variables DisQulck routines use before calling SAVESRANGE or LOADSRANGE. if youre saving any arrays. Also, you'll get an error if ZT is less than ZF+ 1.

INITSVARS allocates all DisQulck simple variables. This is necessary if you're going to call SAVESRANGE and LOADSRANGE, and is good programming practice any time. DisQuick variables all start with a "ZI arbitrarily assigned ZO. the file buffer variable, a 1. Adjust ZZ (maximum arrays for GATHERSWRITE and SCATTERSREAD) as appropriate.

INITSARRAYS allocates space for DisQuick arrays and sets up the Assembly-language subroutine COPYSQWIK. If you will call SAVESRANGE or LOADSRANGE. be sure to call INITSARRAYS after executing all other program dimension statements.

SAVESRANGE and LOADSRANGE represent DisQuick's most powerful routines. They let you read or write the values of all the nonstring simple and array program variables with a single subroutine call. The speed advantage is impressive, especially when you're dealing with large amounts of data. You may also find that using DisQuick reduces the total size of a program, even after adding the DisQuick routines.

You might use these routines as follows: Use SAVESRANGE to write out program data initialized in a temporary subroutine containing assignment and data statements. Then change the program to call LOADSRANGE to do the initialization, and omit the call to SAVESRANGE. When everything works, delete both SAVESRANGE and the conventional initialization subroutine.

The speed and simplicity of these two routines stem from the fact that they don't try to identify individual variables. They simply read or write a range of memory. Thus they will read or write both variable data and Basic's data headers. (The headers Include the identifier characters, data types, array sizes, and so on.)

However, you must be careful If you want to save both simple variables and arrays In the same file. This Is because Basle moves arrays down In memory every time it encounters a new simple variable. Basic thus groups all simple variables, giving you faster access to them. You must therefore declare all simple variables before you call SAVESRANGE. Otherwise, a later call to LOADSRANGE may make your program hang up when Basle tries to access a bombed variable.

You declare a variable by using It. When Basic encounters the statement ZZ ■ 0. it adds a header and data space for ZZ in the variables storage area. Basic assigns variables space in the appropriate section of memory in the order it encounters them.

The Listing covers the variables declaration procedure with the routine INIT-8VARS. Be especially careful not to mix numeric and string variable declarations; you must separate them in memory. The next section should explain why.

What About String Data?

Basic adds string variable headers to variable storage in the same manner it does with other variables. However, the computer puts the character strings themselves in string space, a protected area of RAM.

The string variables contain pointers to string space. If you wrote string variables to a file using DisQuick, you would save only the pointers, not the character data. The pointer values change periodically because of the way Basic manages string space.

You could certainly add DisQuick routines for string data I/O, but why bother? Strings are already in essentially the correct format for text files. Any gain In speed over normal sequential or random-access I/O would likely be offset by the complex processing Involved.

Table 1 compares the size of DisQuick binary files with Disk Basic text flies containing exactly the same randomly generated data. The minimum space savings is over 50 percent for the data used. In other tests of random data. I found the savings as high as 65 percent.

Table 2 compares DisQuick I/O speed with that of Disk Basic PRINT* and INPUT* I/O. again for identical data. DisQuick works up to 13 times as fast as regular text I/O.

Table 3 compares non-I/O uses of DisQuick with conventional Basic programming. You can find uses other than those shown: lines 1280-1340 of the Listing comprise a variation of array-copying that you can use to put random values in an array.

DisQuick Test Program

Lines 100-1340 of the Listing provide a test and example of how you can use DisQuick. It verifies that you've entered DisQuick correctly and that the routines work. You'll need at least 36 grans of free space on your drive-zero disk. Save the program before you run It; if you made any typos, you might bomb RAM.

The program provides examples of ways to call the routines to save or load numeric data in a single array, save or load data In a set of (possibly noncontiguous) numerical arrays. Initialize an array to a constant, and save or load a contiguous set of nonstring variables and arrays.

For the test, you must declare A-Z as integers. For DisQuick routines in your application program, you need only declare Z as an integer; A-Y can be whatever types your application program needs.

"Data size" in these examples refers to the number of bytes of memory allocated for each value. Data size is 2 for an Integer value. 4 for a single-precision value, and 8 for a double-precision value.!

Richard J. Wagner Is a senior software engineer at Floating Point Systems In Beaverton, OR. You can reach him at 11920 N.W. Oatfleld Ct.. Portland. OR 97229.

Circle 99 on Reader Service card.

0 0

Post a comment