COMPDEMO.LST 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. Listing:
  2. 1 MODULE CompDemo;
  3. 2
  4. 3 (* This module demonstrates the use of virtual pointers and the Compact
  5. 4 module to implement a heap the does not suffer from fragmentation.
  6. 5 Note however that the heap is very slow *)
  7. 6
  8. 7 (*%F _fptr *)
  9. 8 This demo program will only work in memory models with far data pointers
  10. 9 (*%E *)
  11. 10
  12. 11 IMPORT Compact,IO,Str;
  13. 12
  14. 13 TYPE
  15. 14 SString=ARRAY[0..63] OF CHAR;
  16. ***** ^ not supported yet
  17. ***** ^ not supported yet
  18. 15 LString=ARRAY[0..255] OF CHAR;
  19. ***** ^ not supported yet
  20. ***** ^ not supported yet
  21. 16 StrP=POINTER TO LString;
  22. ***** ^ not supported yet
  23. 17
  24. 18
  25. 19 INLINE PROCEDURE StrDeref(x:Compact.HandleType):StrP;
  26. ***** ^ not supported yet
  27. 20 BEGIN
  28. 21 RETURN StrP(Compact.DerefHandle(x))
  29. ***** ^ not supported yet
  30. ***** ^ not supported yet
  31. ***** ^ not supported yet
  32. 22 END StrDeref;
  33. ***** ^ not supported yet
  34. 23
  35. 24 TYPE
  36. 25 MovableStrP=VIRTUAL POINTER StrDeref;
  37. ***** ^ not a type name
  38. 26
  39. 27 VAR
  40. 28 StrArray:ARRAY[1..1000] OF MovableStrP;
  41. ***** ^ not supported yet
  42. ***** ^ not supported yet
  43. 29 OK:BOOLEAN;
  44. 30 I,TotDone:CARDINAL;
  45. 31
  46. 32 BEGIN
  47. 33 IO.WrStr('First to allocate as many strings of length 64 as possible');
  48. ***** ^ not supported yet
  49. ***** ^ not supported yet
  50. ***** ^ not supported yet
  51. 34 IO.WrLn;
  52. ***** ^ not supported yet
  53. ***** ^ not supported yet
  54. 35 I:=1;
  55. 36 LOOP
  56. 37 StrArray[I]:=MovableStrP(Compact.Allocate(64));
  57. ***** ^ not supported yet
  58. ***** ^ not supported yet
  59. ***** ^ not supported yet
  60. ***** ^ not supported yet
  61. ***** ^ not supported yet
  62. 38 IF StrArray[I]=MovableStrP(Compact.NotAHandle) THEN EXIT END;
  63. ***** ^ not supported yet
  64. ***** ^ not supported yet
  65. ***** ^ not supported yet
  66. ***** ^ not supported yet
  67. 39 Str.CardToStr(LONGCARD(I),StrArray[I]^,10,OK);
  68. ***** ^ not supported yet
  69. ***** ^ not supported yet
  70. ***** ^ undeclared identifier
  71. ***** ^ not supported yet
  72. ***** ^ not supported yet
  73. ***** ^ not supported yet
  74. ***** ^ not supported yet
  75. 40 I:=I+1
  76. 41 END;
  77. 42 TotDone:=I-1;
  78. 43 IO.WrStr('Able to create ');
  79. ***** ^ not supported yet
  80. ***** ^ not supported yet
  81. ***** ^ not supported yet
  82. 44 IO.WrCard(TotDone,5);
  83. ***** ^ not supported yet
  84. ***** ^ not supported yet
  85. ***** ^ not supported yet
  86. 45 IO.WrStr(' such strings. ');
  87. ***** ^ not supported yet
  88. ***** ^ not supported yet
  89. ***** ^ not supported yet
  90. 46 IO.WrLn;
  91. ***** ^ not supported yet
  92. ***** ^ not supported yet
  93. 47 IO.WrStr('Each contains the string form of the index number');
  94. ***** ^ not supported yet
  95. ***** ^ not supported yet
  96. ***** ^ not supported yet
  97. 48 IO.WrLn;
  98. ***** ^ not supported yet
  99. ***** ^ not supported yet
  100. 49 IO.WrStr('For example Value[100]=');
  101. ***** ^ not supported yet
  102. ***** ^ not supported yet
  103. ***** ^ not supported yet
  104. 50 IO.WrStr(StrArray[100]^);
  105. ***** ^ not supported yet
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. ***** ^ not supported yet
  109. 51 IO.WrLn;
  110. ***** ^ not supported yet
  111. ***** ^ not supported yet
  112. 52 IO.WrStr('Now release every OTHER string leaving lots of 64 byte holes in heap');
  113. ***** ^ not supported yet
  114. ***** ^ not supported yet
  115. ***** ^ not supported yet
  116. 53 IO.WrLn;
  117. ***** ^ not supported yet
  118. ***** ^ not supported yet
  119. 54 I:=1;
  120. 55 WHILE (I<TotDone) DO
  121. 56 Compact.Deallocate(Compact.HandleType(StrArray[I]));
  122. ***** ^ not supported yet
  123. ***** ^ not supported yet
  124. ***** ^ not supported yet
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. ***** ^ not supported yet
  128. 57 I:=I+2;
  129. 58 END;
  130. 59 IO.WrStr('With a normal heap manager the largest element you could allocate would');
  131. ***** ^ not supported yet
  132. ***** ^ not supported yet
  133. ***** ^ not supported yet
  134. 60 IO.WrLn;
  135. ***** ^ not supported yet
  136. ***** ^ not supported yet
  137. 61 IO.WrStr('be 64 bytes. But with this heap manager a request for >64 bytes will');
  138. ***** ^ not supported yet
  139. ***** ^ not supported yet
  140. ***** ^ not supported yet
  141. 62 IO.WrLn;
  142. ***** ^ not supported yet
  143. ***** ^ not supported yet
  144. 63 IO.WrStr('result in a heap compaction freeing up all space to be allocated in');
  145. ***** ^ not supported yet
  146. ***** ^ not supported yet
  147. ***** ^ not supported yet
  148. 64 IO.WrLn;
  149. ***** ^ not supported yet
  150. ***** ^ not supported yet
  151. 65 IO.WrStr('one block. Now to allocate some 256 byte strings.');
  152. ***** ^ not supported yet
  153. ***** ^ not supported yet
  154. ***** ^ not supported yet
  155. 66 I:=1;
  156. 67 LOOP
  157. 68 StrArray[I]:=MovableStrP(Compact.Allocate(256));
  158. ***** ^ not supported yet
  159. ***** ^ not supported yet
  160. ***** ^ not supported yet
  161. ***** ^ not supported yet
  162. ***** ^ not supported yet
  163. 69 IF StrArray[I]=MovableStrP(Compact.NotAHandle) THEN EXIT END;
  164. ***** ^ not supported yet
  165. ***** ^ not supported yet
  166. ***** ^ not supported yet
  167. ***** ^ not supported yet
  168. 70 I:=I+2
  169. 71 END;
  170. 72 IO.WrLn;
  171. ***** ^ not supported yet
  172. ***** ^ not supported yet
  173. 73 IO.WrStr('Managed ');
  174. ***** ^ not supported yet
  175. ***** ^ not supported yet
  176. ***** ^ not supported yet
  177. 74 IO.WrCard((I-1) DIV 2,5);
  178. ***** ^ not supported yet
  179. ***** ^ not supported yet
  180. ***** ^ not supported yet
  181. 75 IO.WrLn;
  182. ***** ^ not supported yet
  183. ***** ^ not supported yet
  184. 76 IO.WrStr('Just to prove the old values have not been lost as a result here is Value[100]');
  185. ***** ^ not supported yet
  186. ***** ^ not supported yet
  187. ***** ^ not supported yet
  188. 77 IO.WrLn;
  189. ***** ^ not supported yet
  190. ***** ^ not supported yet
  191. 78 IO.WrStr('again :');
  192. ***** ^ not supported yet
  193. ***** ^ not supported yet
  194. ***** ^ not supported yet
  195. 79 IO.WrStr(StrArray[100]^);
  196. ***** ^ not supported yet
  197. ***** ^ not supported yet
  198. ***** ^ not supported yet
  199. ***** ^ not supported yet
  200. 80 IO.WrLn;
  201. ***** ^ not supported yet
  202. ***** ^ not supported yet
  203. 81 IO.WrStr('And the really clever thing is that these pointers are dereferenced');
  204. ***** ^ not supported yet
  205. ***** ^ not supported yet
  206. ***** ^ not supported yet
  207. 82 IO.WrLn;
  208. ***** ^ not supported yet
  209. ***** ^ not supported yet
  210. 83 IO.WrStr('using the usual syntax as examining the code will show.');
  211. ***** ^ not supported yet
  212. ***** ^ not supported yet
  213. ***** ^ not supported yet
  214. 84 END CompDemo.
  215. 129 errors