comp.lang.ada
 help / color / mirror / Atom feed
From: Jeff Carter <spam.carter.not@spam.innocon.com>
Subject: Re: Destructor question
Date: 1998/12/07
Date: 1998-12-07T00:00:00+00:00	[thread overview]
Message-ID: <366C005B.F35B96F@spam.innocon.com> (raw)
In-Reply-To: 3666F7F1.9B107D38@nowhere.com

Rusnak wrote:
> ...
>   Sorry about the spelling mistakes on earlier post.  The key terms
> "method" and "attribute" are object-oriented terms (which I believe are now
> accepted as part of UML but I can be wrong about that) and are not
> associated with any particular language.  I would agree that Ada class
> objects do not have a "this" pointer, but tagged records do support
> dispatching operations which are essentially "methods" of the class.

We all make typos, but when we make assumptions about another's typos,
we should make them clear, in case those assumptions are wrong.

There are many who feel a need for new names for concepts that have been
well defined for 30 years under other names, but Ada (ISO/IEC 8652:1995)
is not among them, nor am I. I call a type a type and a subprogram a
subprogram.

More to the point, when discussing Ada, it is helpful to use Ada terms.

> 
> Now to the more important question:  I assume that IF I am going to use the
> Ada.Finalization package, that all my tagged records should be based off of
> the Controlled type within that package.  I would may also have to override
> the Finalize procedure since a derived class could allocate memorey for new
> attributes of the tagged record.  The Finalize, Initialize, and Ajust
> procedures do NOT take an access type however.  What I  have is an array of
> access values to a "'Class" type, and I need to deallocate the memory
> associated with each of the access values.  One cannot write an
> Unchecked_Deallocation for a "'Class" object (this makes sense).  What I

This compiles fine (GNAT 3.10p1/Win95):

with Ada.Finalization;

use Ada;
package Class_Test is
   type T is abstract tagged private;
   
   type T_Ptr is private;
private -- Class_Test
   type T is abstract tagged null record;
   
   type T_Access is access all T'Class;
   
   type T_Ptr is new Finalization.Controlled with record
      Ptr : T_Access;
   end record;
   
   procedure Finalize (Object : in out T_Ptr);
end Class_Test;

with Ada.Unchecked_Deallocation;

use Ada;
package body Class_Test is
   procedure Finalize (Object : in out T_Ptr) is
      procedure Free is new Unchecked_Deallocation
         (Object => T'Class, Name => T_Access);
   begin -- Finalize
      Free (Object.Ptr);
   end Finalize;
end Class_Test;

so possibly you can do what you want directly.

You would need some operations to obtain and manipulate values of type
T_Ptr (these operations might dispatch). You could then declare and
operate on an array of T_Ptr components; when an array object goes out
of scope, its components would be deallocated by finalization.

Note that Ada's design goals include supporting the creation of
readable, easily understood code. The use of type extension and
dispatching results in code that is less readable and more difficult to
understand than code with the same functionality implemented using
composition. Since anything implemented with type extension and
dispatching can be implemented using composition, the only reason to use
type extension and dispatching is to obtain finalization.

-- 
Jeff Carter
E-mail: carter commercial-at innocon [period | full stop] com
"Your mother was a hamster and your father smelt of elderberries."
Monty Python & the Holy Grail




  parent reply	other threads:[~1998-12-07  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-02  0:00 Destructor question Rusnak
1998-12-03  0:00 ` Jeff Carter
1998-12-03  0:00   ` Rusnak
1998-12-04  0:00     ` Robert I. Eachus
1998-12-06  0:00       ` Matthew Heaney
1998-12-08  0:00         ` Robert I. Eachus
1998-12-06  0:00     ` Matthew Heaney
1998-12-07  0:00     ` Jeff Carter [this message]
1998-12-06  0:00 ` david.c.hoos.sr
1998-12-06  0:00   ` Matthew Heaney
1998-12-08  0:00   ` Robert I. Eachus
1998-12-06  0:00 ` Matthew Heaney
replies disabled

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