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,847313ba8810390 X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: Unchecked_Deallocation with tagged types Date: 1996/11/23 Message-ID: #1/1 X-Deja-AN: 198288966 x-nntp-posting-host: pogner.demon.co.uk sender: simon@pogner references: <572uhr$bqf@miso.cs.uq.edu.au> organization: At Home newsgroups: comp.lang.ada Date: 1996-11-23T00:00:00+00:00 List-Id: paulb@cs.uq.edu.au (Paul Burnim) writes: > I'm using my own garbage collection routine for some dynamically > allocated objects, e.g. > > type anytype; > > type anytype_ptr is access all anytype'Class; > > type anytype is tagged record > ..... > end record; > > type r_integer is new anytype with record > val : integer; > end record; > > my question is, if I create an unchecked_deallocation for the type > anytype, will it correctly deallocate an object of the type r_integer, > or do I need to explicitly call an unchecked_deallocation for r_integer. > > e.g. > > procedure Free is new > Unchecked_Deallocation (anytype, anytype_ptr); > > a : anytype_ptr > begin > a := new r_integer'(val => 1, ...) > Free(a); > end; I asked a very similar question yesterday, which hadn't made it onto the Net by this morning. I'd checked the Rationale, FAQ, Barnes, Feldman .. finally check John English's book (Ada 95, the craft of object-oriented programming, ISBN 0-13-230350-7) and there's the answer on page [.. I went straight to it in the bookshop; now where .. ah!] 298. My version is package T is type X is abstract tagged null record; type Xp is access X'Class; procedure Deallocate (The_Xp : in out Xp); end T; with Unchecked_Deallocation; package body T is procedure Free is new Unchecked_Deallocation (X'Class, Xp); procedure Deallocate (The_Xp : in out Xp) renames Free; end T; -- Simon Wright Work Email: simon.j.wright@gecm.com Ferranti Naval Systems Voice: +44(0)1705-701778 GEC-Marconi S3I Combat Systems Division FAX: +44(0)1705-701800