comp.lang.ada
 help / color / mirror / Atom feed
From: chris <spamoff.danx@ntlworld.com>
Subject: Re: Deallocation & Tagged Types
Date: Sun, 19 Oct 2003 17:50:46 +0100
Date: 2003-10-19T17:50:46+01:00	[thread overview]
Message-ID: <Wbzkb.5979$mM1.5916@newsfep4-winn.server.ntli.net> (raw)
In-Reply-To: <bmucnk$r3f6v$1@ID-77047.news.uni-berlin.de>

Dmitry A. Kazakov wrote:
> 
> Same as with any other access type (except an access to subprogram, mind you
> (:-)):
> 
> function Free is
>    new Ada.Unchecked_Deallocation (Vehicle'Class, Vehicle_Access);
> 
> Free (V.Actual);
>    -- Kills V.Actual and sets V.Actual to null,
>    -- or does nothing if V.Actual is already null

Interesting... I didn't know you could do that.  I had tried just 
Vehicle not Vehicle'Class but that was obviously wrong.  I must remember 
that you can instantiate generics like that.


> Note that Free releases a _class-wide_ object. So it first dispatches to
> whatever language-defined finalization is required (for a controlled type
> it is Finalize) then it deallocates the memory.
> 
> BTW, it is better to make Vehicle and Proxy controlled and name Destroy
> "Finalize", which will be then called implicitly, and note always the right
> one. It need not to be abstract because the type Vehicle is already
> abstract, so no harm can be done anyway.

In the code they are Controlled and the Finalization routine does tidy 
up, but it too got stuck at getting rid of V.Actual access variable. 
Now it can go away too.  What is the benefit of making "destroy", 
"finalize"?


Thanks,
Chris




  reply	other threads:[~2003-10-19 16:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-18 20:53 Deallocation & Tagged Types chris
2003-10-19 15:38 ` Robert I. Eachus
2003-10-19 16:53   ` chris
2003-10-20  1:08     ` Robert I. Eachus
2003-10-19 16:10 ` Dmitry A. Kazakov
2003-10-19 16:50   ` chris [this message]
2003-10-20  1:13     ` Robert I. Eachus
2003-10-20  1:43       ` Hyman Rosen
2003-10-26  8:11 ` Patrice Freydiere
replies disabled

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