home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / frame / MENPAT.TXT < prev   
Text File  |  1993-01-03  |  4KB  |  121 lines

  1. Gradual loss of memory in Opl programs with menus
  2. =================================================
  3.  
  4. This note should be read by any party producing commercial Series3
  5. Opl programs with menus.
  6.  
  7. The problem
  8. -----------
  9.  
  10. There are some circumstances in which Opl programs with menus can
  11. gradually lose small amounts of system memory.
  12.  
  13. All memory lost in this way is fully recovered by the Series3 when
  14. the Opl application exits, but if the application runs for a long
  15. time without exiting, it is possible that the cumulative amount of
  16. memory lost will in time adversely affect the performance of the
  17. application.
  18.  
  19. This bug is present in all versions of the Series3.
  20.  
  21. The bug does not affect any programs written in C.
  22.  
  23. The solution
  24. ------------
  25.  
  26. By adding a few extra lines of Opl code to a program, it can be
  27. ensured that no memory loss of this sort will occur.
  28.  
  29. These lines include machine code accessed by the USR keyword, which
  30. have to be typed in exactly correctly, or else random damage might
  31. ensue on the Series3.  In practice, these lines of machine code would
  32. be copied from an existing source, rather than being typed in afresh.
  33.  
  34. The changes required in an Opl program are as follows (or equivalent):
  35.  
  36. 1) Three global arrays have to be declared; their names don't
  37. particularly matter but they could be pt1&(7), pt2&(7), pt3&(8).
  38.  
  39. 2) A call has to be made to a procedure, ptinit: say, in application
  40. start up code, before any call to MENU is made; this routine ptinit:
  41. (source code given below) copies the relevant machine code into the
  42. two arrays pt1&() and pt2&().
  43.  
  44. 3) Instead of calling MENU directly, a procedure menu%:  has to be
  45. defined, which includes one call to USR before the call to MENU, and
  46. another afterwards (see below for an example menu%:).
  47.  
  48. The inconvenience of requiring an extra layer around calls to MENU is
  49. slight, for commercial Opl programs, since these programs are likely
  50. to have such a layer already, for example to make calls to LOCK on
  51. either side of the call to MENU.
  52.  
  53. Further notes:
  54. --------------
  55.  
  56. In the example program below, the program is dominated, size-wise, by
  57. the "patch" code.  However, in a realistic commerical application,
  58. the amount of code in the "patch" will hardly be significant.
  59.  
  60. If desired, the contents of the procedures ptinit:  and menu%: could
  61. of course be placed in-line in the calling procedures.
  62.  
  63. The machine code called by the USR commands automatically detects the
  64. case when no memory has been lost by the MENU command, and does
  65. nothing in this case.
  66.  
  67. It is very unlikely that anyone could notice any speed degradation on
  68. account of calling menu%: each time instead of just MENU.
  69.  
  70. For a further simplification of the patch code, the contents of
  71. ptinit: could be moved inside menu%:, with virtually no detectable
  72. speed degradation, but with the advantage that the three global
  73. arrays can become local variables inside menu%:.
  74.  
  75. There is no need to alter any Opl programs which are only used for
  76. casual purposes, which do not contain MENU calls, or which are only
  77. likely to be run for short periods of time before being exited.
  78.  
  79. Example of changed Opl code
  80. ---------------------------
  81.  
  82.     PROC test:
  83.       global pt1&(7),pt2&(7),pt3&(8)
  84.       local m%
  85.       ptinit:
  86.       do
  87.         mInit
  88.         mCard "Menu 1","Option 1",%a
  89.         mCard "Menu 2","Exit",%x
  90.         m%=menu%:
  91.         if m%=%a
  92.           giPrint "Option 1 selected"
  93.         endif
  94.       until m%=%x
  95.     ENDP
  96.  
  97.     PROC ptinit:
  98.       pt1&(1)=&8BF88BFC
  99.       pt1&(2)=&8B00121E
  100.       pt1&(3)=&778B205F
  101.       pt1&(4)=&E42AAC0C
  102.       pt1&(5)=&A5ABC88B
  103.       pt1&(6)=&75C084AC
  104.       pt1&(7)=&CBF8E2FB
  105.       pt2&(1)=&00B4F08B
  106.       pt2&(2)=&FC808BCD
  107.       pt2&(3)=&AD0D7330
  108.       pt2&(4)=&C932D08B
  109.       pt2&(5)=&CDD88BAD
  110.       pt2&(6)=&F8754ACF
  111.       pt2&(7)=&CB
  112.     ENDP
  113.  
  114.     PROC menu%:
  115.       local r%
  116.       usr(addr(pt1&(1)),addr(pt3&(1)),0,0,0)
  117.       r%=menu
  118.       usr(addr(pt2&(1)),addr(pt3&(1)),0,0,0)
  119.       return(r%)
  120.     ENDP
  121.