comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca>
Subject: Re: Unchecked_Deallocation subtleties
Date: Thu, 10 Apr 2003 12:39:09 -0400
Date: 2003-04-10T12:39:09-04:00	[thread overview]
Message-ID: <3E959E2D.8020200@cogeco.ca> (raw)
In-Reply-To: oprnevwhu4bqmqul@news.cis.dfn.de

Nick Roberts wrote:
> On Wed, 09 Apr 2003 23:39:31 +0200, Samuel Tardieu <sam@rfc1149.net> wrote:
> 
>>>>>>> "Nick" == Nick Roberts <nickroberts@blueyonder.co.uk> 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




  parent reply	other threads:[~2003-04-10 16:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-09  9:10 Unchecked_Deallocation subtleties Piotr Zgorecki
2003-04-09  9:46 ` Samuel Tardieu
2003-04-09 12:19   ` Marin David Condic
2003-04-09 12:37     ` Samuel Tardieu
2003-04-10 12:02       ` Marin David Condic
2003-04-09 16:54     ` Warren W. Gay VE3WWG
2003-04-09 20:19       ` Nick Roberts
2003-04-09 21:39         ` Samuel Tardieu
2003-04-10 11:37           ` Nick Roberts
2003-04-10 14:39             ` Robert Spooner
2003-04-10 16:39             ` Warren W. Gay VE3WWG [this message]
2003-04-09 19:50 ` Nick Roberts
2003-04-10 15:04   ` Nick Roberts
2003-04-10 16:40     ` chris.danx
2003-04-14 23:42   ` Keith Thompson
2003-04-15  1:54     ` Nick Roberts
2003-04-15 12:00     ` Larry Kilgallen
2003-04-15 12:13       ` Jacob Sparre Andersen
2003-04-19  8:57         ` AG
2003-04-09 21:23 ` Randy Brukardt
2003-04-10 11:49   ` Nick Roberts
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox