BASIC-PLUS Virtual Arrays
Virtual Arrays are a feature of BASIC-PLUS that, to the best of my knowledge, were never used in other BASIC implementations.
BASIC-PLUS first appeared on very tiny machines (56KB), but supported up to 12 concurrent users. Virtual arrays are intended to create a poor man’s virtual memory. Virtual arrays are arrays that exist on disk instead of memory. At any point in time, only 512 bytes of the array are stored in memory. This is a pretty severe limitation and has the potential to cause a great deal of thrashing. In the end, it was common to use Virtual Arrays as a random access file mechanism. It was far easier to use than Record I/O, which was intended for random access.
In this article, I’m going to show you some code I tested on the Elvira online RSTS/E System. One of the things I believe you will immediately notice is the use of the percent sign (%) throughout the code. This has always been a mystery to me, but you have to specifically mark all integer constants with the percent sign. If you don’t, the constant will be stored as a floating point constant. Language commands that require an integer will still work if given a floating point number, but will pay a run-time penalty for the conversion to an integer.
Here’s a small program that I put on Elvira:
list
VA 19:12 16-Jan-24
50 input "r or w"; a$
60 if a$="r" then 170
100 dim #1%, a$(10%)
110 open "data.dat" as file 1%
120 for i%=1% to 10%
130 a$(i%)=num$(i%)+" other stuff"
140 next i%
150 close 1%
160 goto 300
170 open "data.dat" as file 1%
180 for i%=1% to 10%
190 print a$(i%)
200 next i%
210 close 1%
300 end
Ready
The program above has two parts to it, one that creates the datafile, lines 100-150, and the other that reads the datafile, lines 170-210.
The “data.dat” file is used to store the data. The open command will either open an existing file or create a new file if it does not currently exist. Other variants of the open command, “open-for input”, and “open-for output” can be used to make sure a file already exists, or to overwrite a file.
If we try reading the DAT file without first writing the file, we will see data that was previously stored on those sectors. Here’s an example
run
VA 19:13 16-Jan-24
r or w? r
tuffdata.datrea
or wrVA.DATDA
10 oth
er stuff19:12
16-Jan-2419:13
4 16-Jan-24r
other stuff
8 other stuff
9 other stuff
10 other stuff
Ready
In this example, you are seeing garbage from prior runs of the program. If I had no prior runs, you would have seen garbage from other users. When I was a kid we called this garbage collection (not to be confused with memory management). We always enjoyed spying on others. If we were lucky we might even find the source code to a system utility. Don’t tell anyone, but when I was 15 y/o I obtained the source code for the SYSTAT program. This was the coolest of all CUSPS (Commonly Used Systems Programs). SYSTAT was a little like “ps -efl” on Linux. With this source code, I was able to get a handle on all the data structures used in the MONITOR (aka Kernel). This was my entry into kernel-level programming, which became my career for 10 years (1984 - 1994).
Here’s an example of how to properly use Virtual Arrays:
run
VA 19:14 16-Jan-24
r or w? w
Ready
run
VA 19:14 16-Jan-24
r or w? r
1 other stuff
2 other stuff
3 other stuff
4 other stuff
5 other stuff
6 other stuff
7 other stuff
8 other stuff
9 other stuff
10 other stuff
Ready
Here we run the program twice, the first to store data and the second to read the stored data.
In this sample, I demonstrated Virtual Arrays with strings, but you can also use integers and floating-point numbers. It is also possible to specify additional arrays in the DIM statement so that multiple arrays can be used in one file. Matrices can also be specified with two dimensions.
In the early 1970s, two companies competed in the education market, Digital Equipment Corporation (DEC), and Hewlett-Packard (HP). Both companies wanted to leverage the pioneering work at Dartmouth College with BASIC and Time-Sharing. They built minicomputers that were much less expensive than the GE Mainframe used at Dartmouth, and much more affordable for secondary schools. In the next article, I will contrast and compare DEC BASIC-PLUS with HP-BASIC. They were very different in how strings and files were handled.