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!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!uucp.gnuu.de!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> <1gv7gza28k9f9$.1njyggeis9jvj.dlg@40tude.net> <1164130167.033602.141630@f16g2000cwb.googlegroups.com> Date: Tue, 21 Nov 2006 19:39:22 +0100 Message-ID: NNTP-Posting-Date: 21 Nov 2006 19:39:15 CET NNTP-Posting-Host: 759a7cca.newsspool4.arcor-online.net X-Trace: DXC=R83hnoAnH^l_0Po7BmQ3]l4IUKcVe4hDNcfSJ;bb[eIRnRBaCd On 21 Nov 2006 09:29:27 -0800, Adam Beneschan wrote: > Dmitry A. Kazakov wrote: > >>>>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. > > To me, if there's a chance that Obj.X won't ever be used for some > particular objects, I don't see any reason to allocate the vector right > away---the allocation can be delayed until it's needed. This may avoid > wasted time and space. Why then X is declared in a scope where it is not used? This violates another good principle: declare objects in the most possible nested scope. > I also don't see why failing to allocate right away would make an > object of type Obj "unusable". A program can still use it if it > accounts for the possibility that X will be null. If Obj is a private > type in a package, and all the operations in that package make sure to > do something appropriate if X is null, then Obj is quite usable. I > very often write code like this, that doesn't bother to allocate until > the package determines that the allocation is necessary. That is OK. It just means that the object size isn't invariant and the object is usable even if not fully allocated. However, it is still a bit suspicious, because it makes the behavior less predictable. Compare it with famous (flawed) OS design which gives you non-committed memory pages so that in sum it could be more than the whole virtual space. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de