How to CLEAR Maximum Amount of Data Space; Heap Space (32327)



The information in this article applies to:

  • Microsoft QuickBASIC 1.0
  • Microsoft BASIC Compiler
  • Microsoft BASIC Interpreter for Apple Macintosh 1.0
  • Microsoft BASIC Interpreter for Apple Macintosh 1.01
  • Microsoft BASIC Interpreter for Apple Macintosh 2.0
  • Microsoft BASIC Interpreter for Apple Macintosh 2.1
  • Microsoft BASIC Interpreter for Apple Macintosh 3.0

This article was previously published under Q32327

SUMMARY

The CLEAR statement can be used to set the maximum amount of data space that a Macintosh BASIC program can use. This information applies to the Microsoft QuickBASIC Compiler Version 1.00, BASIC Compiler Version 1.00, and BASIC Interpreter Versions 1.00, 1.01, 2.00, 2.10, and 3.00 for Apple Macintosh.

The program below sets the maximum amount of data space that can be safely allocated given a set heap space size. The variable heap& should be set to the amount of heap space desired. About 5K serves as a minimum amount for heap space; however, because many programs using ROM routines or system resources require more heap space, it is recommended to use between 50K to 100K for such programs.

MORE INFORMATION

FRE(n), where n is any number or string (except -1 or -2), returns the number of bytes in BASIC's memory space that are not currently being used.

FRE(-1) returns the number of bytes in the Macintosh heap that are not being used by BASIC.

FRE(-2) returns the number of bytes in the stack that have never been used.

The following is a code example:
k&=100   ' Set k& to the number of kilobytes (1024 bytes) of heap desired.
heap&=k& * 1024&
PRINT "data";FRE(0);"heap";FRE(-1);"stack";FRE(-2)

' Subtract the desired heap size from the currently unused
' Datasize + Heapsize:
max& = FRE(0) + FRE(-1) - heap&
PRINT max&, heap&

' This CLEAR sets aside max& data space from the currently unused
' memory, and all other memory is taken by heap and stack:
CLEAR ,max&
PRINT "data";FRE(0);"heap";FRE(-1);"stack";FRE(-2)
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB32327