BASIC compiler memory handling comparison
January 5, 2004

Below are results of tests I did when attempting to migrate from a QBASIC/FirstBasic combination to QuickBASIC and/or PDS 7.1. FirstBasic compiles and executes the code fragment below without a problem: while both Microsoft products compile the fragment OK, either 'out of memory', 'out of string space', 'out of data space', or 'subscript out of range' messages appear at runtime, depending on whether QuickBASIC or PDS 7.1 is used, whether the /AH switch is used, whether PDS's 'far strings' is enabled, and how much memory you've attempted to obtain.

 p.size% = 2000: p.cfgsize% = 25: d.max% = 21
 inimodmax% = 100: inielemax% = 200

 PRINT : PRINT "Begin.": PRINT
 PRINT "free string:"; FRE(""); "bytes"; TAB(27);
 PRINT " array:"; FRE(-1); "bytes"; TAB(49);
 PRINT " stack:"; FRE(-2); "bytes"
 
 PRINT : PRINT "allocating p.size arrays:"
 DIM infile$(p.size%), dirinfo$(p.size%), lst$(p.size%), tmp$(p.size%)
 PRINT "free string:"; FRE(""); "bytes"; TAB(27);
 PRINT " array:"; FRE(-1); "bytes"; TAB(49);
 PRINT " stack:"; FRE(-2); "bytes"
 
 PRINT : PRINT "allocating p.cfgsize arrays.."
 DIM cfg$(p.cfgsize%, 2), dosenvar$(p.cfgsize% * 2)
 PRINT "free string:"; FRE(""); "bytes"; TAB(27);
 PRINT " array:"; FRE(-1); "bytes"; TAB(49);
 PRINT " stack:"; FRE(-2); "bytes"
 
 PRINT : PRINT "allocating menu, drawbox and alt arrays.."
 DIM m.p$(d.max%), m.m$(d.max%), m.d$(d.max%), b.str$(d.max%), alt%(26)
 PRINT "free string:"; FRE(""); "bytes"; TAB(27);
 PRINT " array:"; FRE(-1); "bytes"; TAB(49);
 PRINT " stack:"; FRE(-2); "bytes"
 
 PRINT : PRINT "allocating form arrays.."
 DIM g.p$(d.max%), g.m$(d.max%), g.d$(d.max%), g.i$(d.max%), g.hide%(d.max%)
 DIM g.l%(d.max%), g.lmax%(d.max%), g.c%(d.max%), g.f.x%(d.max%), g.f.y%(d.max%)
 PRINT "free string:"; FRE(""); "bytes"; TAB(27);
 PRINT " array:"; FRE(-1); "bytes"; TAB(49);
 PRINT " stack:"; FRE(-2); "bytes"
 
 PRINT : PRINT "allocating INIMOD array.."
 DIM inimod$(inimodmax%, inielemax%)
 PRINT "free string:"; FRE(""); "bytes"; TAB(27);
 PRINT " array:"; FRE(-1); "bytes"; TAB(49);
 PRINT " stack:"; FRE(-2); "bytes"
 
 PRINT : PRINT "allocating INIELE array.."
 DIM iniele$(inielemax%)
 PRINT "free string:"; FRE(""); "bytes"; TAB(27);
 PRINT " array:"; FRE(-1); "bytes"; TAB(49);
 PRINT " stack:"; FRE(-2); "bytes"
 
 PRINT : PRINT "All arrays allocated."

results for FirstBasic 1.0

Begin.

free string: 32750 bytes   array: 495584 bytes   stack: 522 bytes

allocating p.size arrays:
free string: 32750 bytes   array: 479392 bytes   stack: 522 bytes

allocating p.cfgsize arrays..
free string: 32750 bytes   array: 479056 bytes   stack: 522 bytes

allocating menu, drawbox and alt arrays..
free string: 32750 bytes   array: 478736 bytes   stack: 522 bytes

allocating form arrays..
free string: 32750 bytes   array: 477936 bytes   stack: 522 bytes

allocating INIMOD array..
free string: 32750 bytes   array: 437296 bytes   stack: 522 bytes

allocating INIELE array..
free string: 32750 bytes   array: 436848 bytes   stack: 522 bytes

All arrays allocated.

results for QuickBASIC 4.5

Begin.

free string: 56106 bytes   array: 519978 bytes   stack: 1552 bytes

allocating p.size arrays:
free string: 24058 bytes   array: 487930 bytes   stack: 1552 bytes

allocating p.cfgsize arrays..
free string: 23526 bytes   array: 487398 bytes   stack: 1552 bytes

allocating menu, drawbox and alt arrays..
free string: 23142 bytes   array: 486950 bytes   stack: 1552 bytes

allocating form arrays..
free string: 22758 bytes   array: 486278 bytes   stack: 1552 bytes

allocating INIMOD array..

Subscript out of range in line 0 of module HELLO    at address 0A97:073D

Hit any key to return to system

results for QuickBASIC 4.5 with /AH

Begin.

free string: 56106 bytes   array: 537786 bytes   stack: 1552 bytes

allocating p.size arrays:
free string: 24058 bytes   array: 505738 bytes   stack: 1552 bytes

allocating p.cfgsize arrays..
free string: 23526 bytes   array: 505206 bytes   stack: 1552 bytes

allocating menu, drawbox and alt arrays..
free string: 23142 bytes   array: 504758 bytes   stack: 1552 bytes

allocating form arrays..
free string: 22758 bytes   array: 504086 bytes   stack: 1552 bytes

allocating INIMOD array..

Subscript out of range in line 0 of module HELLO    at address 062A:075B

Hit any key to return to system

results for PDS 7.1 with /AH and near strings

Begin.

free string: 55306 bytes   array: 539466 bytes   stack: 2564 bytes

allocating p.size arrays:
free string: 23258 bytes   array: 507418 bytes   stack: 2564 bytes

allocating p.cfgsize arrays..
free string: 22726 bytes   array: 506886 bytes   stack: 2564 bytes

allocating menu, drawbox and alt arrays..
free string: 22342 bytes   array: 506438 bytes   stack: 2564 bytes

allocating form arrays..
free string: 21958 bytes   array: 505766 bytes   stack: 2564 bytes

allocating INIMOD array..

Subscript out of range in line 0 of module HELLO    at address 062A:073E

Hit any key to return to system

results for PDS 7.1 with /AH and far strings

Begin.

free string: 65430 bytes   array: 533296 bytes   stack: 2394 bytes

allocating p.size arrays:
free string: 65430 bytes   array: 485264 bytes   stack: 2352 bytes

allocating p.cfgsize arrays..
free string: 65430 bytes   array: 484496 bytes   stack: 2348 bytes

allocating menu, drawbox and alt arrays..
free string: 65430 bytes   array: 483888 bytes   stack: 2348 bytes

allocating form arrays..
free string: 65430 bytes   array: 483072 bytes   stack: 2348 bytes

allocating INIMOD array..

Subscript out of range in line 0 of module HELLO    at address 062A:073E

Hit any key to return to system

More on FirstBasic vs. Microsoft here.