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.1 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3dbb4bb0201c39eb X-Google-Attributes: gid103376,public From: Jeff Carter Subject: Re: Destructor question Date: 1998/12/07 Message-ID: <366C005B.F35B96F@spam.innocon.com>#1/1 X-Deja-AN: 419672946 Content-Transfer-Encoding: 7bit References: <3665B85D.A2663591@nowhere.com> <3666BACC.99E6BB06@spam.innocon.com> <3666F7F1.9B107D38@nowhere.com> Content-Type: text/plain; charset=us-ascii Organization: Innovative Concepts, Inc. Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-12-07T00:00:00+00:00 List-Id: 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