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,c4cb2c432feebd9d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!f16g2000cwb.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Finalization Date: 21 Nov 2006 09:29:27 -0800 Organization: http://groups.google.com Message-ID: <1164130167.033602.141630@f16g2000cwb.googlegroups.com> 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> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1164130172 27495 127.0.0.1 (21 Nov 2006 17:29:32 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 21 Nov 2006 17:29:32 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: f16g2000cwb.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:7615 Date: 2006-11-21T09:29:27-08:00 List-Id: 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. 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. Anyway, I don't think it makes sense to say that the vector should be allocated in Initialize, since this is not a real-world example but just a small reduced case, so we don't have enough information about the actual application to say where it's appropriate to do the allocation. -- Adam