QBX Memory Handling

At a Glance

QBX memory AND Capacity

This section explains the factors that affect and control memory management in the QuickBASIC Extended (QBX) environment:

Use of extended and expanded memoryInstallation of device drivers for use with extended and expanded memory.

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Overview of Memory Management

Together, ISAM and QBX require over 450K to run, leaving memory sufficient to develop programs of moderate-size. Fortunately, you can use a variety of techniques to make more memory available for program use:

  • The /Nofrills command-line option reduces the memory QBX uses by 19K. This option reduces some functionality, but requires no special memory boards or device drivers.
  • If you have extended memory, you can move about 60K of the QBX executable code from conventional memory into extended memory, freeing this memory for program use.
  • If you have expanded memory, you can use up to about 1.2 Mb of expanded memory for ISAM buffer space, freeing a significant amount of conventional memory.
    With expanded memory, you can also move certain kinds of program code and data out of conventional memory. The amount of code and data moved depends on how you write your program and what command-line options you give. Using Expanded Memory explains these considerations.
Description

The Extended Memory Specification (XMS) version 2.0 is a convention that allows applications to access a 64K segment of extended memory located just above the 1 MB memory address. This particular segment of extended memory is called the High Memory Area (HMA) and is accessed with the device driver HIMEM.SYS. With a memory board installed and recognized by your computer, the microprocessor treats the HMA as an extension of RAM.

Extended memory can be used only on machines that use an 80286 or later microprocessor chip. The IBM PC, IBM XT and compatible machines cannot use extended memory because the 8088 and 8086 microprocessor chips used in these machines cannot address memory beyond the 1 Mb address.

If you have an EMS (Expanded Memory Specification) board, you may be able to allocate part of its memory (64K is the recommended optimum amount) to extended memory by reconfiguring the board and leaving the rest as expanded memory. Refer to your EMS board manual for more information about reconfiguring your board.

Using Extended Memory

Extended memory can be used to store about 60K of QBX executable code, freeing this memory for program use.

To use extended memory with QBX, you must have:

  • An 80286 or later processor
  • One 64K segment of extended memory located above the 1 MB address
  • The HIMEM.SYS device driver, included with BASIC, installed, or an extended memory device driver that observes the Extended Memory Specification (XMS) version 2.0, installed
Description

Expanded memory is supported by the Lotus/Intel/Microsoft Expanded Memory Specification (LIM EMS) version 4.0, and is accessed via expanded memory managers (EMM), such as the QEMM.SYS, MEMM.SYS, and CEMM.SYS device drivers, as well as by Windows 386. The 386MAX.SYS EMM provides additional expanded memory support, described below.

The 386MAX.SYS expanded memory device driver, by Qualitas, offers the most complete memory support for computers that run on 386 and later processors. It is an expanded memory emulator that allows access to the HMA and possibly to conventional memory for memory-resident programs and certain other programs.

A number of extended memory drivers can utilize some or all extended memory to emulate expanded memory. Use an expanded memory emulator only if you have no expanded memory hardware. All information in "QBX Memory and Capacity" regarding expanded memory hardware applies to expanded memory emulators as well.

To use expanded memory, you must have an expanded memory device driver set in your CONFIG.SYS file. Only one expanded memory device driver can run on the system. (You must reboot for changes in your CONFIG.SYS file to take effect.) Alternatively, you can simply run Windows 386 if you have it installed.

Using Expanded Memory

QBX can use expanded memory to move certain kinds of program code and data out of conventional memory. ISAM can use up to about 1.2 Mb of expanded memory as buffer space for the ISAM Terminate and Stay Resident (TSR) programs. You can set the amount of expanded memory used by ISAM and QBX as decribed below.

ISAM Use of Expanded Memory

By default, the ISAM memory-resident programs use up to approximately 1.2 Mb of expanded memory for buffer space. This frees significant conventional memory and improves ISAM performance, as expanded memory provides more buffers than could exist in conventional memory. ISAM's use of expanded memory can affect how other programs, such as QBX, utilize expanded memory. To limit ISAM's use of expanded memory, use the /Ie option:

/Ie:n option
Where n is the amount of expanded memory, in kilobytes, to reserve for purposes other than ISAM. The default value for n is 0. A value of -1 reserves all expanded memory for non-ISAM uses. The following command line starts ISAM and reserves 800 K of expanded memory for QBX and other uses:

PROISAMD /Ie:800

Use /Ie in conjunction with the /Es option if your program code or a loaded Quick library manages expanded memory (see "QBX Use of Expanded Memory" below). Other ISAM options are discussed in Chapter 10 in the Programmer's Guide, and online in BC Command Line and QBX Command Line.

QBX Use of Expanded Memory

When you load the QBX environment, expanded memory may already be allocated to ISAM or other memory-resident programs. Once inside the QBX environment, you can use the FRE(-3) command to determine how much expanded memory is available for use by QBX. You can affect QBX's use of expanded memory with the options described below.

/E:n option
Where n is the maximum amount of expanded memory, in kilobytes, that QBX can use, out of the total amount of available expanded memory. A value of 0 disables QBX use of expanded memory, and can improve the execution speed of some QBX operations.

If expanded memory is available to QBX, it automatically moves all units of program code between 512 bytes and 16K in size, inclusive, out of conventional memory into expanded memory. Each procedure (function or sub) is a unit of code. The module-level code also constitutes a unit of code.

To see how large each procedure is, use the View Subs command (press F2). You can determine which units are larger than 16K and need to be divided into smaller units.

/Ea option
Moves all arrays, except arrays of variable-length strings, between 512 bytes and 16K in size, inclusive, out of conventional memory and into expanded memory. Arrays residing in expanded memory cannot be passed to mixed-language modules. Do not use /Ea if you pass arrays as parameters to mixed-language Quick library routines. Do not use /Ea with the /Es option.

When you invoke QBX with /Ea and /L, the specified Quick library must have been compiled with the BC /Ah or /D switch. This is necessary because /Ah and /D cause run-time calls instead of inline code generation for array references.

The following QBX command line allows QBX to use 500K of expanded memory and moves arrays into expanded memory:

QBX /E:500 /Ea

/Es option
Saves and restores the expanded memory state before and after every ISAM statement or QBX call to a Quick library, providing that ISAM and QBX are using expanded memory. Enables Quick libraries to use expanded memory directly, by using assembly code that calls for the expanded-memory interrupt. Use /Es only if your Quick library manages expanded memory, since it involves significant overhead. Use of the /E:n option with /Es controls QBX's use of expanded memory and allows sufficient expanded memory for use by Quick libraries. The following QBX command line allows QBX to use 500K of expanded memory and enables saving and restoring of the expanded memory state:

QBX /E:500 /Es

Command-Line Options

Syntax
QBX [/AH] [/B] [/C:buffersize] [{/Ea | /Es}] [/E:n] [/G] [/H] [/K:[keyfile]] [/L [libraryname]] [/MBF] [/Nof[rills]] [/NOHI] [[/RUN] programname] [/CMD string]

These options can be typed on the operating system command line following the QBX command:

Option Description
/AH Allows dynamic arrays of records, fixed-length strings, and numeric data to be larger than 64K each. If /AH is not specified, the maximum size is 64K per dynamic array.
/B Allows the use of a composite (black-and-white) monitor with a color graphics card. The /B option displays QBX in black and white if you have a color monitor.
/C: buffersize Sets the size of the buffer receiving data. This option works only with an asynchronous communications card. The default buffer size is 512 bytes; the maximum size is 32,767 bytes.
/Ea Allows arrays to be moved into expanded memory. /Ea affects arrays with sizes between 512 bytes and 16 kilobytes, inclusive (with the exception of variable-length string arrays, which are never moved into expanded memory). If /Ea is not specified, no arrays are moved into expanded memory.
Do not use /Ea if you pass arrays as parameters to mixed-language Quick library routines. Do not use /Ea with the /Es option.
When you invoke QBX with /Ea and /L, the specified Quick library must have been compiled with the BC /Ah or /D switch. This is necessary because /Ah and /D cause run-time calls instead of inline code generation for array references.
/E:n Limits the amount of expanded memory used by QBX, where n is the amount of memory in kilobytes. If /E:n is not specified, all available expanded memory may be used. A value of 0 disables use of expanded memory by QBX, and can improve the execution speed of some QBX operations.
/Es Allows you to share expanded memory between QBX and Quick libraries or mixed-language routines that make use of expanded memory. Specify /Es when you are using a Quick library or mixed-language routine that makes use of expanded memory. Do not use /Es with the /Ea option.
/G Sets QBX to update a CGA screen as fast as possible. The option works only with machines using CGA monitors. If you see snow (dots flickering on the screen) when QBX updates your screen, then your hardware cannot fully support the /G option. If you prefer a clean screen, restart QBX without this option.
/H Displays the highest resolution possible on your hardware.
/K:[keyfile] Specifies a user-configurable key file to be loaded into QBX. A key file has a .KEY filename extension, and defines key mappings that will be used while editing a file in QBX.
/L [libraryname] Loads the Quick library that is specified by libraryname. If libraryname is not specified, the default Quick library, QBX.QLB, is loaded.
/MBF Causes the QBX conversion functions to treat IEEE-format numbers as Microsoft Binary format numbers.
/Nof Causes QBX to use about 19K less memory, freeing this memory for other uses during program development. These features are unavailable when /Nof is in use: Utility menu and commands, Options menu and commands, and Help menu and commands.
/NOHI Allows the use of a monitor that does not support high intensity. Not for use with Compaq laptop computers.
programname Names the file to be loaded when QBX starts.
/RUN [programname] Causes QBX to load and run the program before displaying it.
/CMD string Passes string to the COMMAND$ function. This option must be the last option on the line.

Syntax
BC sourcefile [objectfile] [listingfile] [optionlist] [;]

These arguments can be typed on the operating system command line following the BC command:

Argument Description
sourcefile The name of your BASIC source code file. If USER is specified, input is taken from the keyboard.
objectfile The name of the object file you are creating.
listingfile The name of the file that will contain an assembly-code source listing of the compiler-generated code. The file contains the address of each line in your source file, the text of the source file, its size, and any error messages produced during compilation. If USER is specified, the listing is sent to the screen.
optionlist One or more of the following command-line options:
Option Description
/? Displays compiler syntax and options.
/A Creates a listing of the disassembled object code for each source line and shows the assembly language code generated by the compiler.
/Ah Allows dynamic arrays of records, fixed-length strings, and numeric data to be larger than 64K each. If /Ah is not specified, the maximum size is 64K per dynamic array.
Be sure to use either /Ah or /D when you are compiling Quick library routines that will be loaded into QBX with the /Ea option (which moves arrays into expanded memory). This is necessary because /Ah and /D cause run-time calls instead of inline code generation for array references.
/C:buffersize Sets the size of the buffer receiving remote data for each communications port when using an asynchronous communications adapter.
/D Generates debugging code for run-time error checking and enables Ctrl+Break. For ISAM programs, causes BASIC to write open database buffers to disk after every DELETE, INSERT, UPDATE, or CLOSE statement.
Be sure to use either /D or /Ah when you are compiling Quick library routines that will be loaded into QBX with the /Ea option (which moves arrays into expanded memory). This is necessary because /D and /Ah cause run-time calls instead of in-line code generation for array references.
/E Specifies presence of ON ERROR with RESUME linenumber statements. (See also the discussion of the /X option in this list.)
/Es Allows you to share expanded memory between BASIC and mixed-language routine(s) that make use of expanded memory. Specify /Es when you are going to use a mixed-language routine that makes use of expanded memory.
/FBr [filename] Generates a file containing restricted program symbol information for use with the Programmer's WorkBench Source Browser. This information file has the name specified by the filename argument. If no name is specified, it has the same name as the source file with an .SBR filename extension. The file contains information about the definitions and references to all global symbols.
/FBx [filename] Generates a file containing extended program symbol information for use with the Programmer's WorkBench Source Browser. This information file has the name specified by the filename argument. If no name is specified, it has the same name as the source file with an .SBR filename extension. The file contains information about the definitions and references to all global and local symbols.
/FPa Causes your program to use the alternate-math library for floating-point operations.
/FPi Causes the compiler to generate in-line instructions for use in floating-point operations.
/Fs Enables far strings in user programs.
/G2 Enables 80286-specific instructions.
/Help Displays online Help for compiler syntax and options.
/Ib Sets the minimum number of buffers to be used by ISAM. ISAM defaults to 6 buffers for reduced functionality (PROISAM) and 9 for full functionality (PROISAMD). The maximum allowable value is 512.
/Ie Sets the amount of expanded memory, in kilobytes, to leave for non-ISAM use when you are working with ISAM. If omitted, all expanded memory (up to about 1.2 megabytes) is used by ISAM. A value of -1 indicates ISAM should use no expanded memory.
/Ii Specifies the number of non-NULL ISAM indexes used in a program. If omitted, the default is 30, which is the minimum value. The maximum allowable value is 500.
/Lp Creates a protected-mode object file; the default if running BC from an OS/2 protected-mode session.
/Lr Creates a real-mode object file; the default if running BC from DOS or an OS/2 real-mode session.
/MBF Allows your BASIC program to read and write floating-point values stored in Microsoft Binary format. The intrinsic functions MKS$, MKD$, CVS, and CVD are converted to MKSMBF$, MKDMBF$, CVSMBF, and CVDMBF, respectively.
/O Substitutes the default stand-alone library for the default run-time library (creates a stand-alone executable file that can run without a BASIC run-time module).
/Ot Optimizes execution speed for SUB and FUNCTION procedures, and DEF FN statements if certain conditions are met. (For conditions, see the Microsoft BASIC Programmer's Guide).
/R Stores arrays in row-major order. BASIC normally stores arrays in column-major order.
/S Writes quoted strings to the object file instead of the symbol table. Use this option when an Out of Memory error message occurs in a program that has many string constants.
/T Suppresses warnings given by the compiler. By default, the interpreter passes this option to BC when you select Make EXE File from the environment.
/V Enables event trapping for communications (COM), lightpen (PEN), joystick (STRIG), timer (TIMER), music buffer (PLAY), function keys (KEY), OS/2 signal events (SIGNAL), and user-defined events (UEVENT). Checks between each BASIC statement for events.
/W Enables event trapping for the same statements as /V, but checks at each line number or label for occurrence of an event.
/X Specifies presence of ON ERROR with RESUME, RESUME NEXT, or RESUME 0.
/Z Produces a listing of compile-time errors in a form readable by the M editor. If used when compiling within M, /Z allows you to locate and scroll through errors in your source and include files by invoking the nxtmsg editor function.
/Zd Produces an object file containing line-number records for debugging purposes corresponding to the line numbers of the source file.
/Zi Adds debugging information to the object file that can be used by the Microsoft CodeView debugger.

Memory Management Utilities

The HIMEM.SYS device driver conforms to the XMS (Extended Memory Specification) version 2.0. It allows MS-DOS programs on 80286 and later systems with extended memory to access an extra 64K segment of memory for code and data. This memory segment is located just above the 1 Mb boundary and is called the High Memory Area. To use HIMEM.SYS with your computer, you must have an 80286 or later processor and DOS version 3.0 or later.

To install HIMEM.SYS, include the following command line in your CONFIG.SYS file:

Device=[d:][path]HIMEM.SYS[/HMAMIN=tsrmin][/NUMHANDLES=handles]

If you install other device drivers that use extended memory calls, place the commands that install them in the CONFIG.SYS file after the above command line.

The HIMEM.SYS device driver syntax contains the following options:

Option Function
tsrmin Specifies the minimum amount of memory, in kilobytes, a Terminate and Stay Resident (TSR) program must have to be placed in the High Memory Area (HMA). The minimum value is 0, the maximum value is 63, and the default value is 0. To ensure that QBX has access to the HMA, set tsrmin to 63 (64,512 bytes).
handles Sets the maximum number of Extended Memory Block (EMB) handles, in kilobytes, that HIMEM.SYS supports. The minimum value is 1, the maximum value is 128, and the default value is 32. Each additional handle requires an additional 6 bytes of resident memory. This option has no effect on the use of extended memory by QBX since these handles give access to addresses above the HMA, which QBX cannot use.

The RAMDRIVE.SYS device driver allows you to use a portion of your computer's memory as an additional hard disk. This disk is referred to as a RAM disk or virtual disk, and it is much faster than a physical hard disk. You can place a RAM disk in conventional, extended, or expanded memory. On most machines, RAMDRIVE.SYS runs fastest on expanded memory. To use RAMDRIVE.SYS with extended memory, you must have an 80286 or later processor, or an AT&T 6300 PLUS.

The system reads and writes to the RAM disk almost as fast as to conventional memory. If you set the TMP environment variable to a directory on a RAM disk, a number of programming tools (notably LINK and ISAM) will use the RAM disk to hold temporary files, thus speeding up operations.

To install RAMDRIVE.SYS, include the following command line in your CONFIG.SYS file:

device=RAMDRIVE.SYS [disksize][sectorsize][entries][{/A | /E | /U}]

The RAMDRIVE.SYS device driver syntax contains the following options:

Option Function
disksize Specifies the disk size in kilobytes. The default size is 64K, the minimum size is 16K, the maximum size is 4096 K.
sectorsize Specifies the sector size in bytes. The default size is 512 bytes. The values 128, 256, 512, and 1024 bytes are allowed.
entries Specifies the number of root directory entries. The default value is 64; the minimum is 2; the maximum is 1024.
RAMDRIVE.SYS adjusts the value of entries to the nearest sector boundary. For example, if you specify a value of 25 when the sector size is 512 bytes, the 25 will be rounded up to 32, which is the next multiple of 16.
/A Lets you use an installed expanded memory board that meets the Lotus/Intel/Microsoft 4.0 Expanded Memory Specification for a RAM drive. The /A, /E, and /U options cannot be used together.
/E Lets you use installed extended memory above 1 Mb as a RAM disk. The /A, /E, and /U options cannot be used together.
/U Specifies that some or all of the 384K of extra memory on the AT&T 6300 PLUS motherboard is to be used as an extra RAM drive. For use on an AT&T 6300 PLUS only. The /A, /E, and /U options cannot be used together.
Note When you reset or turn off you computer's power, the information stored in RAM disks is lost.

SMARTDRIVE is a disk-caching program for computers that have a hard disk and extended memory or expanded memory. A disk cache serves as a temporary holding area for recently-accessed data from the hard disk, and it speeds up disk access.

To install SMARTDRIVE, include the following command line in your CONFIG.SYS file:

device=[d:][path][smartdrv.sys[size][/A]

The SMARTDRV.SYS device driver syntax contains the following options:

Option Function
d: The disk drive where you store SMARTDRV.SYS.
path The directory where you store SMARTDRV.SYS.
size The amount of memory you want SMARTDRV.SYS to have. The default is 256K if it is installed in extended memory; the default is all expanded memory if it is installed in expanded memory. A disk cache must be well over 500K to improve disk access significantly.
/A Use this option if you have expanded memory.