home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ZSYS / SIMTEL20 / SYSLIB / SYSLIB.LBR / SYSLIBI.HQP / SYSLIBI.HLP
Text File  |  2000-06-30  |  6KB  |  159 lines

  1. Memory Allocation Concept
  2. ALLOC  -- Allocate a Block of Memory
  3. IALLOC -- Initialize Memory Allocation System
  4. :Memory Allocation Concept
  5.  
  6.      Thσ concep⌠ oµ memor∙ allocatioε witΦ thesσ routine≤ i≤ ì
  7. relativel∙á simple«á  Routine≤á arσá provideΣá t∩á givσá thσ ì
  8. programme≥áá simplσá memor∙á allocatioεáá anΣáá deallocatioε ì
  9. capabilities¼ bu⌠ thσ programme≥ i≤ stil∞ iε control.
  10.  
  11.      Thσá basiπá ideß herσ i≤ t∩ reservσ ß buffe≥ iεá memor∙ ì
  12. froφá whicΦá t∩ takσ bit≤ anΣ piece≤ froφ a⌠á ßá time«á  Thσ ì
  13. boundinτá addresse≤ oµ thi≤ buffe≥ arσ specifieΣ (o≥ se⌠á b∙ ì
  14. default⌐á b∙ thσ IALLO├ routine¼á anΣ thσ ALLO├á routinσá i≤ ì
  15. useΣá t∩ obtaiε subbuffer≤ froφ thi≤ large≥ buffe≥ froφ timσ ì
  16. t∩ time«á  ALLO├ constantl∙ check≤ t∩ seσ iµ thσ buffe≥á ha≤ ì
  17. enougΦ spacσ lef⌠ t∩ gran⌠ thσ reques⌠ fo≥ ß subbuffer¼ and¼ ì
  18. if it does, the subbuffer is provided.
  19.  
  20.      Thσ larges⌠ buffe≥ whicΦ ma∙ bσ reserveΣ b∙ thσá IALLO├ ì
  21. routinσá i≤á tha⌠ buffe≥ whicΦ extend≤ froφ thσ enΣá oµá thσ ì
  22. prograφá t∩ jus⌠ belo≈ thσ CCP«á  Thi≤ buffe≥ i≤ selecteΣ iµ ì
  23. IALLO├ i≤ calleΣ witΦ A=0.
  24.  
  25.  
  26.      Fo≥ example¼á thσ followinτ illustrate≤ thσ applicatioε ì
  27. using the largest buffer possible:
  28.  
  29.           XRA  A    ; Select Full Buffer
  30.           CALL IALLOC
  31.           ...
  32.           LXI  D,1024    ; Request 1K
  33.           CALL ALLOC
  34.           JZ   MEMOVFL   ; Abort if Memory Overflow
  35.           SHLD BUF1      ; Set Pointer to First Subbuffer
  36.           ...
  37.           LXI  D,36      ; Request 36 bytes
  38.           CALL ALLOC
  39.           JZ   MEMOVFL   ; Abort if Memory Overflow
  40.           SHLD BUF2      ; Set Pointer to 2nd Subbuffer
  41.           ...
  42.  
  43.  
  44.      Thi≤ memor∙ allocatioε schemσ als∩ permit≤ thσ divisioε ì
  45. oµá memor∙á int∩á ß grou≡ oµ buffers«á  Onσá buffe≥á ma∙á bσ ì
  46. allocated¼á it≤á addres≤ preserved¼á anothe≥ buffe≥á ma∙á bσ ì
  47. allocated¼á it≤ addres≤ preserved¼ anΣ theε subsequen⌠ call≤ ì
  48. t∩á IALLO├á ma∙ bσ useΣ t∩ selec⌠ onσ buffe≥ o≥á thσá other«  ì
  49. EacΦá cal∞ t∩ IALLO├ free≤ thσ entirσ buffe≥ area¼á s∩á carσ ì
  50. should be taken in doing this.  For example:
  51.  
  52.           ...
  53.           CALL CODEND    ; Use Codend as First Buffer
  54.           SHLD BUF1
  55.           XCHG           ; Address in DE
  56.           LXI  H,1024    ; 1K for this buffer
  57.           DAD  D         ; HL pts to after this buffer
  58.           XCHG           ; HL is start, DE is end
  59.           MVI  A,3       ; Select Start and End
  60.           CALL IALLOC
  61.           ...
  62.  
  63.  
  64. IALLOC/ALLOC Example, Con't
  65.  
  66.           ...
  67.           CALL ALLOC     ; Calls to ALLOC
  68.           ...
  69.           LHLD BUF1      ; Pt to 1st Buffer
  70.           LXI  D,1024    ; Set 2nd Buffer
  71.           DAD  D         ; Pt to 2nd Buffer
  72.           SHLD BUF2
  73.           XCHG
  74.           DAD  D         ; Pt to end of 2nd Buffer (1K also)
  75.           XCHG           ; HL is start, DE is end
  76.           MVI  A,3       ; Select Start and End
  77.           CALL IALLOC
  78.           ...
  79.           CALL ALLOC     ; Calls to ALLOC
  80.           ...
  81.  
  82. :Allocate a Block of Memory
  83.      Routine:  ALLOC
  84.  
  85.      Function:
  86.  
  87.      ALLO├á allocate≤á ß blocδ oµ memory¼á whicΦ ma∙á bσá a≤ ì
  88. smal∞ a≤ onσ byte¼ fo≥ thσ use≥ froφ thσ buffe≥ poo∞ boundeΣ ì
  89. b∙á thσ value≤ se⌠ b∙ ß preceedinτ cal∞ t∩á IALLOC«á  IALLO├ ì
  90. mus⌠ bσ calleΣ beforσ ALLO├ i≤ used.
  91.  
  92.      Thσ programme≥ indicate≤ thσ numbe≥ oµ byte≤ hσá wishe≤ ì
  93. t∩ usσ iε thσ D┼ registe≥ pair«  Hσ theε call≤ ALLOC¼ which¼ ì
  94. iµá enougΦá spacσ i≤ available¼á return≤ thσ addres≤ oµá thσ ì
  95. firs⌠ bytσ oµ tha⌠ blocδ oµ memor∙ iε HL«  Thσ PS╫ return≤ ß ì
  96. flaτ sayinτ iµ thσ allocatioε wa≤ donσ successfully.
  97.  
  98.  
  99.      Inputs:  DE = number of bytes requested
  100.  
  101.      Outputs:  HL = Address of first byte allocated
  102.                A=░ anΣ Zer∩ Flaτ Se⌠ (Z⌐ iµ no⌠ enougΦ space;
  103.                A=0FFH and Zero Flag Reset (NZ) if request
  104.                     granted
  105.  
  106.      Registers Affected:  HL, PSW
  107.  
  108.      SYSLIB Routines Called:  None
  109.  
  110.      Special Error Conditions:  As indicated by return code
  111.  
  112. :Initialize Memory Allocation Buffer
  113.      Routine:  IALLOC
  114.  
  115.      Function:
  116.  
  117.      IALLO├áá initialize≤á thσá buffe≥á froφá whicΦáá memor∙ ì
  118. allocatioεá vißá call≤ t∩ thσ ALLO├ routinσ i≤ t∩á bσá done«  ì
  119. Thσá programme≥ ma∙ specif∙ thσ bound≤ oµá thi≤á buffer¼á o≥ ì
  120. defaul⌠ bound≤ wil∞ bσ se⌠ b∙ IALLO├ iµ nonσ arσ specified.
  121.  
  122.      Upoεá callinτá IALLOC¼á H╠á ma∙á contaiεá thσá startinτ ì
  123. addres≤ oµ thσ buffe≥ area«  Iµ i⌠ doe≤ not¼ theε thσ enΣ oµ ì
  124. thσá user'≤á prograφ (returneΣ b∙ CODEND⌐ i≤ used«á  D┼á ma∙ ì
  125. contaiε thσ endinτ addres≤ oµ thσ buffe≥ area«á  Iµ i⌠á doe≤ ì
  126. not¼á theεá thσ bytσ belo≈ thσ CC╨ i≤ used«á  Thσ ┴ registe≥ ì
  127. contain≤ ß codeΣ flaτ sayinτ whicΦ boundar∙ value≤ t∩ use.
  128.  
  129.  
  130. IALLOC, Con't
  131.  
  132.      Iµ Bi⌠ ░ oµ ┴ i≤ 1¼ H╠ i≤ useΣ t∩ indicatσ thσ startinτ ì
  133. addres≤ oµ thσ buffer«  Iµ Bi⌠ ░ i≤ 0¼ thσ valuσ returneΣ b∙ ì
  134. CODEN─á i≤ used«á  Iµ Bi⌠ ▒ oµ ┴ i≤ 1¼á D┼ i≤ t∩ bσ useΣá t∩ ì
  135. indicatσ thσ endinτ addres≤ oµ thσ buffer«á  Iµ Bi⌠ ▒ i≤á 0¼ ì
  136. thσ bytσ belo≈ thσ CC╨ i≤ used.
  137.  
  138.      Inputs:  HL = Possible Starting Address of Buffer
  139.               DE = Possible Ending Address of Buffer
  140.               A = Selection Code:
  141.                 Bit 0 - Use HL as Starting Address if 1
  142.                         Use CODEND Value if 0
  143.                 Bit 1 - Use DE as Ending Address if 1
  144.                         Use CCP-1 if 0
  145.  
  146.      Outputs:  None
  147.  
  148.      Registers Affected:  None
  149.  
  150. IALLOC, Con't
  151.  
  152.      SYSLIB Routines Called:  CODEND
  153.  
  154.      Special Error Conditions:  None
  155.  
  156.  
  157.  
  158.  
  159.