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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,927ae253da8bb547 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-30 12:33:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Specialization Date: 30 May 2002 15:20:56 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <4519e058.0205300909.5bfb317d@posting.google.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1022786898 21100 128.183.220.71 (30 May 2002 19:28:18 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 30 May 2002 19:28:18 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:25030 Date: 2002-05-30T19:28:18+00:00 List-Id: "Baugereau" writes: > > "Baugereau" wrote in message > news:... > > > For instance, when I empty the container, I want to Finalize all the > > > elements if they are Controlled, and do nothing if not. > > > > Why wouldn't that happen automaticly? If you want to *manually* > > control finalization, you probably shouldn't be using controlled > > types. > > I have this interface in my package (I snipped) > > > with Ada.Finalization; > use Ada.Finalization; > generic > type ELEMENT is private; > package Vector is > Default_Reserved : constant NATURAL := 32; > Growth : constant NATURAL := 32; > type ELEMENTPTR is access all ELEMENT; > type ELEMENTS is array(NATURAL range <>) of aliased ELEMENT; This is the problem. You should (almost certainly :) have an array of ELEMENTPTR, not an array of ELEMENT. When an element is added to Vector, you call 'new' for it. When an element is erased from the vector you call an instantiation of Unchecked_Deallocation on it. Then Finalize will be called automatically, if necessary. See the file sal-poly-unbounded_arrays.ads in SAL at http://users.erols.com/leakstan/Stephe/Ada/sal.html for an example of a similar package. You will find that you will have to allow your generic ELEMENT type to be unconstrained and/or indefinite, if the Vector package is to be truly useful. For example, try to define a Vector of String. Once you do that, you are forced to have an array of pointer-to-element. -- -- Stephe