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 >
Text File  |  1991-09-11  |  5KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  PARADOX                                NUMBER  :  542
  9.   VERSION  :  ALL
  10.        OS  :  DOS
  11.      DATE  :  September 11, 1991                       PAGE  :  1/4
  12.  
  13.     TITLE  :  STACK SPACE/PAL ALLOCATION OF STACKS
  14.  
  15.  
  16.  
  17.  
  18.   This is an explanation of why the error "Run out of stack space"
  19.   is displayed by Paradox.
  20.  
  21.   Stack space problems are the result of scripts or procedures
  22.   calling each other.  The Paradox stack is used to keep track of
  23.   the script (or procedure) active at any time and which scripts
  24.   have been played.
  25.  
  26.   The stack works on the premise that the last item placed on the
  27.   stack must be cleared before accessing any other item, sometimes
  28.   referred to as LIFO (Last In, First Out).  This means that each
  29.   new procedure you call is placed on the stack, pushing down the
  30.   previous procedure.  In order to develop an understanding of the
  31.   discussion, let's work with some examples.
  32.  
  33.   If script FIRST calls script SECOND, the stack would look like
  34.   this:
  35.  
  36.        FIRST
  37.        SECOND
  38.  
  39.   Then, SECOND calls script FIRST again and now the stack becomes:
  40.  
  41.        FIRST
  42.        SECOND
  43.        FIRST
  44.  
  45.   This can continue until all the stack space is used up. The way
  46.   to prevent this recursive system from filling up all the stack
  47.   space is to use the RETURN command detailed on page 371 of the
  48.   PAL User's Guide.  Using RETURN on the stack problem yields the
  49.   following allocation of stack space:
  50.  
  51.        FIRST
  52.        SECOND
  53.  
  54.   If script SECOND uses RETURN, instead of issuing PLAY FIRST,
  55.   SECOND will be "popped off" the stack, and control returns to
  56.   script FIRST.  Now the stack looks like this:
  57.  
  58.        FIRST
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  PARADOX                                NUMBER  :  542
  75.   VERSION  :  ALL
  76.        OS  :  DOS
  77.      DATE  :  September 11, 1991                       PAGE  :  2/4
  78.  
  79.     TITLE  :  STACK SPACE/PAL ALLOCATION OF STACKS
  80.  
  81.  
  82.  
  83.  
  84.   All of this information holds true whether you are using scripts
  85.   or procedures.  The use of the WHERE? (press [Ctrl-W]) command is
  86.   very useful in locating where recursion happens.  Page 126 of the
  87.   PAL User's Guide explains the usage of WHERE?.
  88.  
  89.   The following pages contain scripts demonstrating the incorrect
  90.   method and correct method for stack usage.
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  PARADOX                                NUMBER  :  542
  141.   VERSION  :  ALL
  142.        OS  :  DOS
  143.      DATE  :  September 11, 1991                       PAGE  :  3/4
  144.  
  145.     TITLE  :  STACK SPACE/PAL ALLOCATION OF STACKS
  146.  
  147.  
  148.  
  149.  
  150.   release vars all
  151.   ;This script demonstrates a STACK OVERFLOW error.
  152.   ;
  153.   ;--------------What NOT to DO-----------------
  154.   Proc main()                            ;Proc starts
  155.   Showmenu                               ;a menu
  156.   "Recursive" : "play this several times (15 or 20 to get debug)",
  157.   "Quit"      : "Quit"
  158.       to z                               ;to a variable
  159.       Switch
  160.           case z = "Recursive":          ;if they select this choice
  161.              jcdowrong()                 ;call jcdowrong procedure
  162.           case z = "Quit":
  163.              message "Adios"             ;if they select quit
  164.              sleep 750                   ;give a message
  165.       Endswitch
  166.   EndProc
  167.  
  168.   Proc jcdowrong()                       ;the bad procedure
  169.      if not isassigned(z1)
  170.      then z1 = 1
  171.      endif
  172.       Message "looped " + strval(z1)+ " times"
  173.       z1=z1+1
  174.       sleep 200
  175.       main()                             ;this is the offending line
  176.   EndProc
  177.  
  178.   Main()                                 ;the actual script
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  PARADOX                                NUMBER  :  542
  207.   VERSION  :  ALL
  208.        OS  :  DOS
  209.      DATE  :  September 11, 1991                       PAGE  :  4/4
  210.  
  211.     TITLE  :  STACK SPACE/PAL ALLOCATION OF STACKS
  212.  
  213.  
  214.  
  215.  
  216.   ; Rather than call the original procedure, let the procedure
  217.   ; return naturally or use a "return" command
  218.   ;----------------What to DO------------------
  219.  
  220.   Proc goodmain()                        ;Proc starts
  221.   While(true)                            ;use the loop to eliminate
  222.   having to
  223.                                          ;to recursive calls
  224.   Showmenu                               ;a menu
  225.   "NON-Recursive" : "play this several times(15 or 20 to get debug)",
  226.                                          ;the choices
  227.   "Quit"          : "Quit"
  228.       to z                               ;to a variable
  229.       Switch
  230.           case z = "NON-Recursive":      ;if they select this choice
  231.              jcdoright()                 ;call jcdoright procedure
  232.           case z = "Quit":
  233.              message "Adios"             ;if they select quit
  234.              sleep 750                   ;give a message
  235.              quitloop
  236.       Endswitch
  237.   endwhile
  238.   EndProc
  239.  
  240.  
  241.   Proc jcdoright()
  242.      if not isassigned(z2)
  243.      then z2 = 1
  244.      endif
  245.       Message "looped " + strval(z2)+ " times"
  246.       z2=z2+1
  247.       sleep 200
  248.   EndProc
  249.  
  250.   goodmain()
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.