| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- Listing:
- 1 MODULE CompDemo;
- 2
- 3 (* This module demonstrates the use of virtual pointers and the Compact
- 4 module to implement a heap the does not suffer from fragmentation.
- 5 Note however that the heap is very slow *)
- 6
- 7 (*%F _fptr *)
- 8 This demo program will only work in memory models with far data pointers
- 9 (*%E *)
- 10
- 11 IMPORT Compact,IO,Str;
- 12
- 13 TYPE
- 14 SString=ARRAY[0..63] OF CHAR;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 15 LString=ARRAY[0..255] OF CHAR;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 16 StrP=POINTER TO LString;
- ***** ^ not supported yet
- 17
- 18
- 19 INLINE PROCEDURE StrDeref(x:Compact.HandleType):StrP;
- ***** ^ not supported yet
- 20 BEGIN
- 21 RETURN StrP(Compact.DerefHandle(x))
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 22 END StrDeref;
- ***** ^ not supported yet
- 23
- 24 TYPE
- 25 MovableStrP=VIRTUAL POINTER StrDeref;
- ***** ^ not a type name
- 26
- 27 VAR
- 28 StrArray:ARRAY[1..1000] OF MovableStrP;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 29 OK:BOOLEAN;
- 30 I,TotDone:CARDINAL;
- 31
- 32 BEGIN
- 33 IO.WrStr('First to allocate as many strings of length 64 as possible');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 34 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 35 I:=1;
- 36 LOOP
- 37 StrArray[I]:=MovableStrP(Compact.Allocate(64));
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 38 IF StrArray[I]=MovableStrP(Compact.NotAHandle) THEN EXIT END;
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 39 Str.CardToStr(LONGCARD(I),StrArray[I]^,10,OK);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 40 I:=I+1
- 41 END;
- 42 TotDone:=I-1;
- 43 IO.WrStr('Able to create ');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 44 IO.WrCard(TotDone,5);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 45 IO.WrStr(' such strings. ');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 46 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 47 IO.WrStr('Each contains the string form of the index number');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 48 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 49 IO.WrStr('For example Value[100]=');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 50 IO.WrStr(StrArray[100]^);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 51 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 52 IO.WrStr('Now release every OTHER string leaving lots of 64 byte holes in heap');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 53 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 54 I:=1;
- 55 WHILE (I<TotDone) DO
- 56 Compact.Deallocate(Compact.HandleType(StrArray[I]));
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 57 I:=I+2;
- 58 END;
- 59 IO.WrStr('With a normal heap manager the largest element you could allocate would');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 60 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 61 IO.WrStr('be 64 bytes. But with this heap manager a request for >64 bytes will');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 62 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 63 IO.WrStr('result in a heap compaction freeing up all space to be allocated in');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 64 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 65 IO.WrStr('one block. Now to allocate some 256 byte strings.');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 66 I:=1;
- 67 LOOP
- 68 StrArray[I]:=MovableStrP(Compact.Allocate(256));
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 69 IF StrArray[I]=MovableStrP(Compact.NotAHandle) THEN EXIT END;
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 70 I:=I+2
- 71 END;
- 72 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 73 IO.WrStr('Managed ');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 74 IO.WrCard((I-1) DIV 2,5);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 75 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 76 IO.WrStr('Just to prove the old values have not been lost as a result here is Value[100]');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 77 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 78 IO.WrStr('again :');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 79 IO.WrStr(StrArray[100]^);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 80 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 81 IO.WrStr('And the really clever thing is that these pointers are dereferenced');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 82 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 83 IO.WrStr('using the usual syntax as examining the code will show.');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 84 END CompDemo.
- 129 errors
|