comp.lang.ada
 help / color / mirror / Atom feed
From: "Norman H. Cohen" <ncohen@watson.ibm.com>
Subject: Re: Deallocation via class-wide pointer
Date: 1996/11/25
Date: 1996-11-25T00:00:00+00:00	[thread overview]
Message-ID: <3299F143.4A4E@watson.ibm.com> (raw)
In-Reply-To: x7vralm3vqf.fsf@luthien.frlngtn.gmcs.gecm.com


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




      reply	other threads:[~1996-11-25  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-22  0:00 Deallocation via class-wide pointer Simon Wright
1996-11-25  0:00 ` Norman H. Cohen [this message]
replies disabled

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