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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2ce943dcc1eb3f9c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!75g2000cwc.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: How to properly clean up an extended, generic structure? Date: 9 Jul 2006 07:29:24 -0700 Organization: http://groups.google.com Message-ID: <1152455364.613074.18170@75g2000cwc.googlegroups.com> References: <44b107b7$0$3629$4d3efbfe@news.sover.net> NNTP-Posting-Host: 69.170.65.169 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1152455370 24643 127.0.0.1 (9 Jul 2006 14:29:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 9 Jul 2006 14:29:30 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 75g2000cwc.googlegroups.com; posting-host=69.170.65.169; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news2.google.com comp.lang.ada:5575 Date: 2006-07-09T07:29:24-07:00 List-Id: Peter C. Chapin wrote: > I've created a procedure Destroy_Tree that uses an instance of > Ada.Unchecked_Deallocation to remove all the nodes in a given tree. > Destroy_Tree is meant to be used when a tree is no longer needed and it > serves the role of a destructor (using C++ terminology). It occurs to > me, though, that Item_Type might have its own clean up needs. I assume > that Unchecked_Deallocation knows nothing about that. Thus my code > currently might be improperly cleaning up the Item_Types in each tree > node. In C++ this is not a problem because deleting a node invokes the > node's destructor (if there is one) so the issue is handled > automatically. My question is how do I best deal with this in Ada? > > I could pass a clean up procedure for Item_Types as another generic > parameter. However, in cases where no such procedure is necessary (for > example, when Item_Type is just Integer), such a solution seems awkward. > Is there a nicer solution? You should read up on Ada controlled types. The tree itself can be a controlled type. The tree elements may or may not be controlled types. Ada controlled types allow you to specify actions to be taken upon initialization, adjustment, and finalization of a data element. These actions effectively mimic many of the characteristics of C++ constructors and destructors. Jim Rogers