home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 22238 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  2.4 KB

  1. Path: sparky!uunet!opl.com!hri.com!spool.mu.edu!agate!dog.ee.lbl.gov!ucbvax!ACCESS.DIGEX.COM!tdarcos
  2. From: tdarcos@ACCESS.DIGEX.COM (Paul Robinson)
  3. Newsgroups: comp.os.vms
  4. Subject: [TDR] VAX Pascal Dispose
  5. Message-ID: <Pine.3.05.9301271029.D3981-c100000@access>
  6. Date: 27 Jan 93 15:35:29 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Organization: The Internet
  9. Lines: 78
  10.  
  11.  
  12.  F>I have a question about how can I prove or disprove that the 
  13.   >DISPOSE procedure in Vax Pascal does really return the storage 
  14.   >space pointed to by the parameter of the dispose procedure to 
  15.   >the system's free space so that it can be reused.
  16.  
  17.  F>All Comments welcome,
  18.  
  19. To do this you need to be able to "see" a pointer which you can't do
  20. because the compiler usually won't let you look at them directly, like
  21. this:
  22.  
  23. PROGRAM DUMPPTR(OUTPUT);
  24. TYPE 
  25.      ILP = ^IL;
  26.      IL = RECORD
  27.             DValue : Integer;
  28.             PREV,NEXT: ILP;
  29.           END;       
  30.     (* 1 *)      
  31.  
  32. VAR
  33.      V1,V2,V3: ILP;
  34.     (* 2 *)
  35.  
  36. begin
  37.     new(V1);
  38.     writeln(v1);
  39.     new(v2);
  40.     writeln(V2);   (* 3 *)
  41.     dispose(V2);
  42.     new(v3);
  43.     writeln(V3);    (* The second two output lines *)
  44.                     (* should be identical *)
  45. end.
  46.  
  47. This won't work because you can't write a pointer out (most Pascals won't
  48. allow it, anyway).  So you have to fool the compiler, by inserting code at
  49. points 1,2 and 3.  So we have the following:
  50.  
  51. PROGRAM ImprovedDump(OUTPUT);
  52.  
  53. TYPE  
  54.      ILP = ^IL;
  55.      IL = RECORD
  56.             DValue : Integer;
  57.             PREV,NEXT: ILP;
  58.           END;
  59.       SW = RECORD
  60.               CASE boolean OF
  61.                  true: (P: ILP);
  62.                 false: (I: INTEGER);
  63.            END;
  64.  
  65. VAR
  66.      V1,V2,V3: ILP;
  67.      T: SW;
  68.  
  69. BEGIN
  70.         new(V1);
  71.         T.P := V1;
  72.         WRITELN(T.I);
  73.         new(v2);
  74.         T.P := V2;
  75.         WRITELN(T.I);
  76.         dispose(v2);
  77.         new(v3);
  78.         T.P := V3;
  79.         WRITELN(T.I);  (* The second two output lines should be *)
  80.                        (* identical *)
  81.  end.
  82.  
  83. The construct SW and the T variable are sometimes called "pornographic"
  84. memory access because this is something Pascal provides that usually only
  85. C programmers can have: access to any memory anywhere.  By simply
  86. assigning an integer value to T.I and reading it with, say, T.P, it is
  87. possible to examine any location in memory.  This is a "kluge" to fool the
  88. compiler which doesn't know what we are trying to accomplish.
  89.