comp.lang.ada
 help / color / mirror / Atom feed
* Deallocation via class-wide pointer
@ 1996-11-22  0:00 Simon Wright
  1996-11-25  0:00 ` Norman H. Cohen
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Wright @ 1996-11-22  0:00 UTC (permalink / raw)



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);

This must be a common problem, I guess I'm just looking at it wrong;
any thoughts?


-- 
Simon Wright                                    (G-net) +842-1778
Ferranti Naval Systems                  (voice) +44(0)1705-701778
GEC-Marconi S3I Combat Systems Division   (fax) +44(0)1705-701800




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Deallocation via class-wide pointer
  1996-11-22  0:00 Deallocation via class-wide pointer Simon Wright
@ 1996-11-25  0:00 ` Norman H. Cohen
  0 siblings, 0 replies; 2+ messages in thread
From: Norman H. Cohen @ 1996-11-25  0:00 UTC (permalink / raw)



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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-11-25  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-22  0:00 Deallocation via class-wide pointer Simon Wright
1996-11-25  0:00 ` Norman H. Cohen

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