Can't Increase Stack in Interpreter (Macintosh QuickBASIC) (52048)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0

This article was previously published under Q52048

SUMMARY

In the interpreter environment in Microsoft QuickBASIC for Macintosh, the stack is set to its maximum by default. In the interpreter, the CLEAR statement can only make the stack smaller. The only reason you would want to set the stack smaller in the interpreter would be to make more heap space.

Note that this article does not apply to compiled programs in QuickBASIC, just to interpreted programs. The stack is handled completely differently in compiled programs and can be larger than 32K, as explained in a separate article that can be found by querying on the following words:

Macintosh and QuickBASIC and compiled and memory and map and correction

MORE INFORMATION

The stack in the QuickBASIC interpreter environment is also used by the Macintosh System, thus making the stack difficult to predict or control from your program. Normally, you should never need to change the stack in the interpreter -- the stack is handled automatically.

If your goal is to increase heap space (with the CLEAR statement) in the interpreter, it is better to decrease the data space and leave the stack space alone. This is because if the stack ever runs into the heap at run time and you decreased the stack size with CLEAR, you may get a System Error ID=28 and must reboot. If you instead leave the stack size at its default and the stack runs into the heap, then the interpreter gracefully gives an "Out of Memory", Error 7 (which can optionally be trapped with the ON ERROR GOTO statement), and no reboot is needed.

The CLEAR statement can change the stack size as follows:
   CLEAR ,datasegmentsize,stacksize
				
or
   CLEAR ,,stacksize
				
The stacksize parameter of the CLEAR statement must be from 1K to 32K in the interpreter. Attempting to use a size larger than 32K gives an "Overflow" error for the CLEAR. In the interpreter, the default stack size is about 40K (but may vary on different Macintosh System versions) and cannot be made larger.

If you CLEAR the stack size once in an interpreted program, you cannot CLEAR the stack larger, only smaller. (In a compiled program, you can define the stack larger or smaller than the previous CLEAR; however, Microsoft advises using the CLEAR statement only once at the beginning of a compiled or interpreted program.)

The FRE(-2) function returns the number of bytes never used by the stack since the program started. FRE(-2) is not very useful, except when FRE(-2) approaches zero, which means that stack space almost ran out at some previous point in the program. The values returned by FRE(-2) always decrease (or stay the same) during the course of a program and never increase.

According to a test program using the default stack, the interpreter can perform 2748 GOSUB statements without RETURNing, after which you receive "Out of Memory" (Error 7).

If you CLEAR,,32760 then you can perform about 2039 GOSUBs without RETURN, after which you get System Error ID=28 (Stack Ran into Heap). If you CLEAR,,8000 then you can perform only about 492 GOSUBs without RETURN, after which you get System Error ID=28.

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB52048