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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,afda15cf2a9aa1ca X-Google-Attributes: gid103376,public From: "Norman H. Cohen" Subject: Re: Deallocation via class-wide pointer Date: 1996/11/25 Message-ID: <3299F143.4A4E@watson.ibm.com>#1/1 X-Deja-AN: 200681733 references: content-type: text/plain; charset=us-ascii organization: IBM Thomas J. Watson Research Center mime-version: 1.0 reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; I) Date: 1996-11-25T00:00:00+00:00 List-Id: Simon Wright wrote: > I have a type T and a class-wide pointer: > > type T is tagged with null record; > type TP is access T'Class; > > I have a queue of T's (and, of course, types extended from T) to > process. The individual objects are allocated dynamically and put into > some Queue package, which manages TP's. > > What I want to do is to pop the objects off the queue, process them > (via some appropriate dispatching operation) and then deallocate the > memory. > > For the life of me I can't see how to get to call > > type TPP is access T; > procedure Free is new Unchecked_Deallocation (T, TPP); Instantiate Ada.Unchecked_Deallocation as follows instead: procedure Free is new Ada.Unchecked_Deallocation (T'Class, TP); The resulting Free can be used to deallocate anything that was allocated by an allocator of the form new T'Class(x) appearing in a context where a value of type TP is expected. (The value x in this allocator is allowed to belong to any specific type descended from T.) -- Norman H. Cohen mailto:ncohen@watson.ibm.com http://www.research.ibm.com/people/n/ncohen