comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: Deallocating an object referenced via a classwide access type.
Date: 2000/01/11
Date: 2000-01-11T00:00:00+00:00	[thread overview]
Message-ID: <387BBEE4.74607ED8@averstar.com> (raw)
In-Reply-To: slrn87l2rt.15e.aidan@skinner.demon.co.uk

Aidan Skinner wrote:
> 
> Mkay.
> 
> I have the following package:
> 
> with Ada.Finalization;
> package Foo_Package is
> 
>   type Foo is new Ada.Finalization.Controlled with private;
> 
>   type Foo_Access is access all Foo'Class;
> 
>   type New_Foo is new Foo with private;
> 
> private
> 
>   type Foo is new Ada.Finalization.Controlled with record
>      My_Thing : Foo_Access := null;
>   end Foo;
> 
>   type New_Foo is new Foo with null record;
> 
>   procedure Deallocate (Object : in out Foo);
> 
> end Foo_Package;
> 
> How do I deallocate My_Thing?
> 
> I can't use Ada.Unchecked_Deallocation, since My_Thing might be a Foo
> or it might be a New_Foo.

That is not your concern.  The run-time system knows which is
which, because of the presence of the run-time tag.  What matters is
which access type you use when instantiating Unchecked_Deallocation --
so long as you instantiate using Foo_Access/Foo'Class as the
actual parameters, it should work fine.

The only problem in this general vicinity is that if you allocate
using one access type, you must deallocate using an access type
that uses the same storage pool (RM95 13.11.2(16)).  
The safest thing is to allocate and deallocate using 
the same access type, but you can also specify all of your 
access types to use the same storage pool by adding something like:
   for Fum_Access'Storage_Pool use Foo_Access'Storage_Pool;
to all other access types to which you might convert a value of
type Foo_Access.
> 
> A quick search through the RM and various text books has proven
> fruitless. :((
> 
> - Aidan

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




  parent reply	other threads:[~2000-01-11  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-11  0:00 Deallocating an object referenced via a classwide access type Aidan Skinner
2000-01-10  0:00 ` Matthew Heaney
2000-01-11  0:00   ` Matthew Heaney
2000-01-11  0:00 ` Tucker Taft [this message]
2000-01-11  0:00 ` Laurent Guerby
replies disabled

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