home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!opl.com!hri.com!spool.mu.edu!agate!dog.ee.lbl.gov!ucbvax!ACCESS.DIGEX.COM!tdarcos
- From: tdarcos@ACCESS.DIGEX.COM (Paul Robinson)
- Newsgroups: comp.os.vms
- Subject: [TDR] VAX Pascal Dispose
- Message-ID: <Pine.3.05.9301271029.D3981-c100000@access>
- Date: 27 Jan 93 15:35:29 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Organization: The Internet
- Lines: 78
-
-
- F>I have a question about how can I prove or disprove that the
- >DISPOSE procedure in Vax Pascal does really return the storage
- >space pointed to by the parameter of the dispose procedure to
- >the system's free space so that it can be reused.
-
- F>All Comments welcome,
-
- To do this you need to be able to "see" a pointer which you can't do
- because the compiler usually won't let you look at them directly, like
- this:
-
- PROGRAM DUMPPTR(OUTPUT);
- TYPE
- ILP = ^IL;
- IL = RECORD
- DValue : Integer;
- PREV,NEXT: ILP;
- END;
- (* 1 *)
-
- VAR
- V1,V2,V3: ILP;
- (* 2 *)
-
- begin
- new(V1);
- writeln(v1);
- new(v2);
- writeln(V2); (* 3 *)
- dispose(V2);
- new(v3);
- writeln(V3); (* The second two output lines *)
- (* should be identical *)
- end.
-
- This won't work because you can't write a pointer out (most Pascals won't
- allow it, anyway). So you have to fool the compiler, by inserting code at
- points 1,2 and 3. So we have the following:
-
- PROGRAM ImprovedDump(OUTPUT);
-
- TYPE
- ILP = ^IL;
- IL = RECORD
- DValue : Integer;
- PREV,NEXT: ILP;
- END;
- SW = RECORD
- CASE boolean OF
- true: (P: ILP);
- false: (I: INTEGER);
- END;
-
- VAR
- V1,V2,V3: ILP;
- T: SW;
-
- BEGIN
- new(V1);
- T.P := V1;
- WRITELN(T.I);
- new(v2);
- T.P := V2;
- WRITELN(T.I);
- dispose(v2);
- new(v3);
- T.P := V3;
- WRITELN(T.I); (* The second two output lines should be *)
- (* identical *)
- end.
-
- The construct SW and the T variable are sometimes called "pornographic"
- memory access because this is something Pascal provides that usually only
- C programmers can have: access to any memory anywhere. By simply
- assigning an integer value to T.I and reading it with, say, T.P, it is
- possible to examine any location in memory. This is a "kluge" to fool the
- compiler which doesn't know what we are trying to accomplish.
-