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-Thread: 103376,c4cb2c432feebd9d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!newsfeed.utanet.at!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Finalization Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <0ugu4e.4i7.ln@hunter.axlog.fr> <%P_cg.155733$eR6.26337@bgtnsc04-news.ops.worldnet.att.net> <6H9dg.10258$S7.9150@news-server.bigpond.net.au> <1hfv5wb.1x4ab1tbdzk7eN%nospam@see.signature> <2006052509454116807-gsande@worldnetattnet> Date: Tue, 21 Nov 2006 12:09:20 +0100 Message-ID: <1gv7gza28k9f9$.1njyggeis9jvj.dlg@40tude.net> NNTP-Posting-Date: 21 Nov 2006 12:09:20 CET NNTP-Posting-Host: 81557ed5.newsspool3.arcor-online.net X-Trace: DXC=OC=>BUH3ik4lIh70@7enW;^6ZC`4F0oL On Tue, 21 Nov 2006 11:32:31 +0100, Philippe Tarroux wrote: >>Note that Obj is declared Controlled, not Limited_Controlled, therefore the >>function Process would make a copy of it. >> > If I declare it Limited_Controlled I can't use the function version > anymore. Right? Sort of, actually, in Ada 2005 there is a way to return limited objects. > But I don't undestand why it works for the first 7 iteration of the loop > and crashes only at the 8th. That depends on how fast the memory vital for further program execution gets corrupt... (:-)) >>Do it this way: >> >> for I in 1 .. 100 loop >> declare >> O : Obj; -- Ideally Initialize should allocate the vector >> begin >> Process (O); -- Don't allocate anything here >> > You mean that there should be no allocation here? vector is allocated > inside process. I would allocate vector in Initialize, at least to separate object construction from object's use. Of course the design depends on what you are going to do, especially, on whether the object size is dynamic and changes during the object's life span or not. If the object's size is invariant, then it makes no sense to delay any allocation of its parts. Also, independently, it is a good design principle to ensure object's usability during all its lifespan. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de