Microsoft KB Archive/47758

From BetaArchive Wiki
Knowledge Base

SETMEM(0) Returns Total Heap, FRE(-1) Returns Available Heap

Article ID: 47758

Article Last Modified on 11/21/2006


  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0

This article was previously published under Q47758


The program shown below demonstrates the difference between the SETMEM(0) and FRE(-1) functions. SETMEM(0) returns the TOTAL possible amount of far heap space, while FRE(-1) returns the far heap space minus any data (in DGROUP or far heap) that is currently allocated. For Microsoft Basic PDS Version 7.00, FRE(-1) refers only to far heap; to get available expanded memory you must use FRE(-3).

This information applies to QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS, and to Microsoft Basic PDS Version 7.00 for MS-DOS.


The following program is MEMSIZE.BAS, which invokes SETMEM(0) and FRE(-1) before and after allocating a data string:

PRINT "Setmem                        : "; SETMEM(0)
PRINT "Nonstring array             -1: "; FRE(-1)
a$ = SPACE$(200)
PRINT "      --- After Allocation ---"
PRINT "Setmem                        : "; SETMEM(0)
PRINT "Nonstring array             -1: "; FRE(-1)

After the string is allocated, SETMEM(0) returns the same value as it did before the call. FRE(-1), however, is decreased by the size of the string (200 bytes for the string plus 2 bytes for the string descriptor).

Additional query words: QuickBas BasicCom

Keywords: KB47758