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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e589dbfe40b0d25 X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: Deallocating an object referenced via a classwide access type. Date: 2000/01/11 Message-ID: <387BBEE4.74607ED8@averstar.com>#1/1 X-Deja-AN: 571401096 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-01-11T00:00:00+00:00 List-Id: 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