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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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 10:27:51 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!isdnet!wanadoo.fr!not-for-mail From: "Baugereau" Newsgroups: comp.lang.ada Subject: Re: Specialization Date: Thu, 30 May 2002 19:29:53 +0200 Organization: Wanadoo, l'internet avec France Telecom Message-ID: References: <4519e058.0205300909.5bfb317d@posting.google.com> Reply-To: "Baugereau" NNTP-Posting-Host: afontenayssb-103-1-4-21.abo.wanadoo.fr X-Trace: wanadoo.fr 1022779670 15915 80.11.133.21 (30 May 2002 17:27:50 GMT) X-Complaints-To: abuse@wanadoo.fr NNTP-Posting-Date: 30 May 2002 17:27:50 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 Xref: archiver1.google.com comp.lang.ada:25018 Date: 2002-05-30T17:27:50+00:00 List-Id: > "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; type ELEMENTSPTR is access ELEMENTS; type VECTOR is new CONTROLLED with record Size : NATURAL; Reserved : NATURAL; Data : ELEMENTSPTR; end record; -- Controlled type procedure Initialize (obj : in out VECTOR); procedure Finalize (obj : in out VECTOR); procedure Adjust (obj : in out VECTOR); -- Custom function Get (obj : in VECTOR; index : in NATURAL) return ELEMENTPTR; function Get (obj : in VECTOR; index : in NATURAL) return ELEMENT; procedure Push_Back (obj : in out VECTOR; elt : in ELEMENT); procedure Empty (obj : in out VECTOR); procedure Erase (obj : in out VECTOR; first : in NATURAL; last : in NATURAL); private procedure Realloc (obj : in out VECTOR; new_reserved : in POSITIVE); end Vector; the goal is to have Data as a raw storage of ELEMENTs that I can extend when I Push_Back elements in the VECTOR... Data has Reserved elements but only Size elements are meaningful. And if I push_back a lot of elements, I don't want to realloc the storage each time, so I make it grow linearly (for now). Then when I erase, reserved must stay the same, size should become 0, and objects in the storage should be finalized if they are not trivial. Is it clear this time? Sorry I'm not a native speaker :) Is this inherently flawed? Should I not bother with growing Data by myself? I don't think so, because I think "new" is costly (it is just a belief :) )