home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / bbs / picsuncr.arc / TPHEAP.DOC < prev    next >
Text File  |  1991-08-11  |  6KB  |  147 lines

  1.  
  2.                   TURB╧ PASCA╠ HEA╨ MANAGEMENT
  3.                       W« BRIMHAL╠  13DEC87
  4.                      ZNOD┼ 5▓ (602)996-8739
  5.  
  6.                             OVERVIEW
  7. 
  8. Thi≤ filσ contain≤ informatioε t∩ supplemen⌠ thσ Dynamiπ Storagσ ì
  9. sectioε oµ thσ CP/═ 8░ Turb∩ Pasca∞ ver≤ 3.░ referencσ manua∞ ì
  10. whicΦ doe≤ no⌠ adequatel∙ cove≥ thesσ topics:
  11.  
  12.      1⌐ Changinτ thσ addres≤ oµ thσ heap.
  13.      2⌐ Preservinτ thσ hea≡ durinτ ß prograφ chain.
  14.  
  15. ┴ cal∞ t∩ BorlanΣ technica∞ suppor⌠ diΣ no⌠ improvσ thσ situatioε ì
  16. s∩ thσ followinτ informatioε wa≤ obtaineΣ froφ severa∞ hour≤ oµ ì
  17. disassembl∙ anΣ debugging.
  18.  
  19. Firs⌠ oµ al∞ ß CO═ filσ produceΣ b∙ Turb∩ Pasca∞ follow≤ thi≤ ì
  20. genera∞ memor∙ map:
  21.  
  22. HIG╚ MEMORY     ---------------------------------
  23.                               bdos
  24.                 ---------------------------------
  25.                           variablσ area
  26.                 ---------------------------------
  27.                  prograφ stacδ   (growinτ down)
  28.                 ---------------------------------
  29.                  recursioε stacδ (growinτ down)
  30.                         hea≡ (growinτ up)
  31.                 ---------------------------------
  32.                           prograφ code
  33.                 ---------------------------------
  34.                          runtimσ library
  35.                 ---------------------------------
  36.                     pagσ ░ vector≤ ª pointers
  37. LO╫ MEMOR┘      ---------------------------------
  38.  
  39. Turb∩ maintain≤ thesσ ▓ hea≡ pointer≤ iε pagσ 0:
  40.  
  41. 00C┤  HEAPPTR║ d≈ ░  ;pointe≥ t∩ star⌠ oµ freσ memor∙ a⌠ to≡ oµ heap
  42. 00D┤  HEAPFRE║ d≈ ░  ;pointe≥ t∩ 1s⌠ blocδ oµ freσ memor∙ iε heap
  43.  
  44. HeapPt≥ i≤ predefineΣ anΣ caε bσ accesseΣ likσ an∙ intege≥ ì
  45. variable« HeapFrσ i≤ no⌠ eveε mentioneΣ iε thσ Turb∩ Referencσ ì
  46. manual« I⌠ mus⌠ bσ declareΣ a≤ aε absolutσ variablσ beforσ i⌠ can
  47. bσ accessed:
  48.                   Var
  49.                     HeapFrσ ║ intege≥ absolutσ $00de;
  50.  
  51. Wheε ß Turb∩ prograφ run≤ o≥ execute≤ HeapPtr ª HeapFre arσ botΦ ì
  52. se⌠ t∩ thσ firs⌠ bytσ pas⌠ thσ enΣ oµ thσ prograφ code« Thi≤ i≤ ì
  53. wherσ thσ hea≡ begins« Thσ firs⌠ ┤ byte≤ oµ thσ hea≡ arσ theε ì
  54. cleareΣ t∩ zero« 
  55. è
  56. Wheε memor∙ i≤ firs⌠ allocateΣ oε thσ hea≡ witΦ thσ NE╫ procedurσ ì
  57. i⌠ wil∞ bσ placeΣ a⌠ thσ locatioε addresseΣ b∙ HeapPtr« Therσ i≤ ì
  58. ß ┤ bytσ overheaΣ fo≥ eacΦ blocδ tha⌠ i≤ allocated¼ s∩ bytes¼ ì
  59. chars¼ ª integer≤ wil∞ al∞ usσ u≡ ┤ byte≤ oµ storagσ oε thσ heap« ì
  60. Thσ ┤ byte≤ followinτ thσ newl∙ allocateΣ blocδ wil∞ alway≤ bσ ì
  61. zeroeΣ t∩ marδ thσ to≡ oµ thσ heap.
  62.  
  63. Wheε storagσ i≤ reclaimeΣ witΦ thσ DISPOS┼ procedurσ ß linkeΣ ì
  64. lis⌠ i≤ createΣ startinτ witΦ thσ lowes⌠ freσ blocδ iε thσ ì
  65. heap« Thσ addres≤ oµ thi≤ blocδ i≤ placeΣ iε HeapFre« Thσ firs⌠ ┤ ì
  66. byte≤ oµ eacΦ freσ blocδ iε thσ hea≡ contaiε linδ pointer≤ iε ì
  67. thi≤ format:
  68.  
  69.      d≈ nex⌠   ╗addres≤ oµ nex⌠ freσ block
  70.      d≈ sizσ   ;sizσ oµ thi≤ freσ block
  71.  
  72. Thσ to≡ oµ thσ hea≡ alway≤ contain≤ ┤ byte≤ oµ ░ whicΦ marδ the
  73. enΣ oµ thσ linδ list.
  74.  
  75. Thσ actua∞ pointe≥ variable≤ arσ storeΣ a≤ integers« Iµ the∙ arσ ì
  76. declareΣ globall∙ the∙ wil∞ bσ placeΣ iε thσ variablσ areß whicΦ ì
  77. i≤ no⌠ affecteΣ b∙ chain≤ o≥ execute≤ a≤ lonτ a≤ thσ chaineΣ ì
  78. program≤ don'⌠ overwritσ tha⌠ sectioε oµ memory.
  79.  
  80.  
  81.                    T╧ CHANG┼ TH┼ HEA╨ ADDRESS
  82. 
  83. Thσ Turb∩ Referencσ manua∞ give≤ thσ impressioε tha⌠ thσ hea≡ ì
  84. addres≤ caε bσ changeΣ simpl∙ b∙ assigninτ ß ne≈ valuσ t∩ ì
  85. HeapPtr« Thi≤ i≤ no⌠ correctí  T∩ changσ thσ hea≡ addres≤ t∩ thσ ì
  86. valuσ Θ yo⌡ must:
  87.  
  88.      1⌐ Declarσ followinτ variable≤:ì
  89.  
  90.           Var
  91.             Θ ║ integer;
  92.             HeapFrσ ║ intege≥ absolutσ $00de;
  93.  
  94.      2⌐ Rese⌠ HeapPtr¼ HeapFrσ ª firs⌠ ┤ byte≤ oµ heap:
  95.  
  96.           HeapPtr:=i;    √ Se⌠ hea≡ pointe≥ t∩ addres≤ ne≈ hea≡ }
  97.           HeapFre:=i╗    √ Se⌠ freσ meφ pt≥ t∩ addres≤ ne≈ heap}
  98.           fo≥ i:=░ t∩ │ do
  99.            mem[HeapPtr+i]:=0╗ √ Zer∩ 1s⌠ ┤ byte≤ oµ ne≈ hea≡ }
  100.  
  101. RecurPt≥ i≤ anothe≥ predefineΣ variablσ tha⌠ addresse≤ thσ ì
  102. recursioε stack« Makσ surσ HeapPt≥ i≤ neve≥ greate≥ thaε RecurPt≥ ì
  103. anΣ tha⌠ HeapPtr i≤ alway≤ addressinτ ß freσ memor∙ area!
  104. .PAè
  105.                T╧ PRESERV┼ TH┼ HEA╨ DURIN╟ ┴ CHAIN
  106. 
  107.      Thσ Turb∩ loade≥ overwrite≤ u≡ t∩ 12╕ byte≤ oµ raφ abovσ thσ ì
  108. prograφ codσ witΦ ß CO═ filσ wheε i⌠ i≤ loadeΣ froφ disδ witΦ thσ ì
  109. executσ command« Thi≤ overwritteε memor∙ i≤ thσ firs⌠ 12╕ byte≤ ì
  110. oµ thσ heap« T∩ preservσ thσ hea≡ durinτ ß chaiε thi≤ blocδ mus⌠ ì
  111. bσ saveΣ alonτ witΦ thσ hea≡ pointers« Thesσ value≤ caε theε bσ ì
  112. restoreΣ a≤ follow≤ afte≥ thσ chaiε o≥ executσ i≤ performed:
  113.  
  114.      1⌐ Declarσ followinτ globa∞ variable≤ anΣ makσ surσ al∞ ì
  115. ááááápointe≥ variable≤ arσ global:
  116.  
  117.           Var
  118.             heap,heap_ptr,heap_frσ ║ integer;
  119.             HeapFrσ ║ intege≥ absolutσ $00de;
  120.             heap_byte≤ ║ arra∙[0..127▌ oµ byte;
  121.  
  122. ááááá2⌐ Savσ hea≡ addres≤ wheε prograφ starts.ì
  123.  
  124.           heap:=HeapPtr;
  125.  
  126.      3⌐ Savσ 1s⌠ 128 byte≤ oµ heap¼ HeapPt≥ ª HeapFrσ jus⌠ beforσ         ì
  127. áááááchaining«          
  128.  
  129.           heap_fre:=HeapFre;
  130.           heap_ptr:=HeapPtr;
  131.           fo≥ i:=░ t∩ 12╖ do
  132.            heap_bytes[i]:=mem[heap+i]);
  133.  
  134.      4⌐ Chaiε t∩ othe≥ prograφ anΣ executσ bacδ t∩ maiε program« ì
  135. áááááMakσ surσ thσ chaineΣ prograφ doe≤ no⌠ overwritσ an∙ othe≥ ì
  136. áááááarea≤ oµ thσ hea≡ o≥ variablσ area!
  137.  
  138.      5⌐ Restorσ saveΣ value≤ beforσ accessinτ heap:
  139.  
  140.           HeapPtr:=heap_ptr;
  141.           HeapFre:=heap_fre;
  142.           fo≥ i:╜ ░ t∩ 127 do
  143.             mem[heap+i]:=heap_bytes[i];
  144.  
  145. ááááá6⌐ Thσ hea≡ i≤ no≈ completel∙ restoreΣ anΣ caε no≈ bσ ì
  146. áááááaccesseΣ a≤ thougΦ thσ chaiε neve≥ tooδ place« 
  147.