home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware 1 2 the Maxx
/
sw_1.zip
/
sw_1
/
TEXT
/
PDX_ALL.ZIP
/
TI542.ASC
< prev
next >
Wrap
Text File
|
1991-09-11
|
5KB
|
265 lines
PRODUCT : PARADOX NUMBER : 542
VERSION : ALL
OS : DOS
DATE : September 11, 1991 PAGE : 1/4
TITLE : STACK SPACE/PAL ALLOCATION OF STACKS
This is an explanation of why the error "Run out of stack space"
is displayed by Paradox.
Stack space problems are the result of scripts or procedures
calling each other. The Paradox stack is used to keep track of
the script (or procedure) active at any time and which scripts
have been played.
The stack works on the premise that the last item placed on the
stack must be cleared before accessing any other item, sometimes
referred to as LIFO (Last In, First Out). This means that each
new procedure you call is placed on the stack, pushing down the
previous procedure. In order to develop an understanding of the
discussion, let's work with some examples.
If script FIRST calls script SECOND, the stack would look like
this:
FIRST
SECOND
Then, SECOND calls script FIRST again and now the stack becomes:
FIRST
SECOND
FIRST
This can continue until all the stack space is used up. The way
to prevent this recursive system from filling up all the stack
space is to use the RETURN command detailed on page 371 of the
PAL User's Guide. Using RETURN on the stack problem yields the
following allocation of stack space:
FIRST
SECOND
If script SECOND uses RETURN, instead of issuing PLAY FIRST,
SECOND will be "popped off" the stack, and control returns to
script FIRST. Now the stack looks like this:
FIRST
PRODUCT : PARADOX NUMBER : 542
VERSION : ALL
OS : DOS
DATE : September 11, 1991 PAGE : 2/4
TITLE : STACK SPACE/PAL ALLOCATION OF STACKS
All of this information holds true whether you are using scripts
or procedures. The use of the WHERE? (press [Ctrl-W]) command is
very useful in locating where recursion happens. Page 126 of the
PAL User's Guide explains the usage of WHERE?.
The following pages contain scripts demonstrating the incorrect
method and correct method for stack usage.
PRODUCT : PARADOX NUMBER : 542
VERSION : ALL
OS : DOS
DATE : September 11, 1991 PAGE : 3/4
TITLE : STACK SPACE/PAL ALLOCATION OF STACKS
release vars all
;This script demonstrates a STACK OVERFLOW error.
;
;--------------What NOT to DO-----------------
Proc main() ;Proc starts
Showmenu ;a menu
"Recursive" : "play this several times (15 or 20 to get debug)",
"Quit" : "Quit"
to z ;to a variable
Switch
case z = "Recursive": ;if they select this choice
jcdowrong() ;call jcdowrong procedure
case z = "Quit":
message "Adios" ;if they select quit
sleep 750 ;give a message
Endswitch
EndProc
Proc jcdowrong() ;the bad procedure
if not isassigned(z1)
then z1 = 1
endif
Message "looped " + strval(z1)+ " times"
z1=z1+1
sleep 200
main() ;this is the offending line
EndProc
Main() ;the actual script
PRODUCT : PARADOX NUMBER : 542
VERSION : ALL
OS : DOS
DATE : September 11, 1991 PAGE : 4/4
TITLE : STACK SPACE/PAL ALLOCATION OF STACKS
; Rather than call the original procedure, let the procedure
; return naturally or use a "return" command
;----------------What to DO------------------
Proc goodmain() ;Proc starts
While(true) ;use the loop to eliminate
having to
;to recursive calls
Showmenu ;a menu
"NON-Recursive" : "play this several times(15 or 20 to get debug)",
;the choices
"Quit" : "Quit"
to z ;to a variable
Switch
case z = "NON-Recursive": ;if they select this choice
jcdoright() ;call jcdoright procedure
case z = "Quit":
message "Adios" ;if they select quit
sleep 750 ;give a message
quitloop
Endswitch
endwhile
EndProc
Proc jcdoright()
if not isassigned(z2)
then z2 = 1
endif
Message "looped " + strval(z2)+ " times"
z2=z2+1
sleep 200
EndProc
goodmain()