From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b2dd3ff35d68d825 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-10 09:41:49 PST Message-ID: <3E959E2D.8020200@cogeco.ca> From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Unchecked_Deallocation subtleties References: <87smssj94u.fsf@inf.enst.fr> <3E94502E.6070108@cogeco.ca> <87llyj5p0s.fsf@inf.enst.fr> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 10 Apr 2003 12:39:09 -0400 NNTP-Posting-Host: 198.96.47.195 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1049992748 198.96.47.195 (Thu, 10 Apr 2003 12:39:08 EDT) NNTP-Posting-Date: Thu, 10 Apr 2003 12:39:08 EDT Organization: Bell Sympatico Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!torn!webster!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Xref: archiver1.google.com comp.lang.ada:36061 Date: 2003-04-10T12:39:09-04:00 List-Id: Nick Roberts wrote: > On Wed, 09 Apr 2003 23:39:31 +0200, Samuel Tardieu wrote: > >>>>>>> "Nick" == Nick Roberts writes: >>>>>> >> >> Nick> Consider the following example skeleton piece of code: >> >> Nick> declare >> Nick> X: Some_Access_Type; >> Nick> begin >> Nick> ... -- [1] >> Nick> Y := X.all; -- [2] last use of X >> Nick> ... -- [3] >> Nick> Free(X); -- [4] >> Nick> end; >> >> Nick> Although it may be that no compiler would (or even could) do so >> Nick> in practice, other rules in the ARM made it theoretically >> Nick> possible for the implementation to automatically reclaim the >> Nick> storage occupied by whatever X pointed to (assuming no other >> Nick> access value pointed to it) at any point in the elided code >> Nick> section [3]. >> >> I would say that Free(X) is certainly a use of X, so the last use of X >> is not in [2], it is in [4]. > > Hmmmm. Obviously you are right, Sam, on the face of it. Theoretically > (there's that word again), a compiler could apply a special rule to an > instance of Unchecked_Deallocation (that, for each call, the object > pased to it is not considered to have been used), on the basis that this > would never do any harm and might provide opportunities for earlier > automatic storage reclamation. In practice I doubt any compiler has ever > actually done this. Maybe I am looking at this incorrectly, but the most obvious place to do garbage collection here (if implemented) is at the end of the declare/begin block. At the "end" statement, there is no more doubt that the value X is no longer in use ;-) , despite any contortions that might be present in the code. So if I were implementing garbage collection, the point of the "end" statement would be where an effective "Free(X)" behind the scenes would be implied, if necessary. While the code executes within that block, there is no need to fuss over whether X is being used or not. In fact that would be rather difficult to predict when X was no longer required if you have goto's and such present. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg