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,4e04f7888d82ca71 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s72.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Efficiency of returning big objects References: <4npvh0FbgbuhU1@individual.net> In-Reply-To: <4npvh0FbgbuhU1@individual.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s72 1159212707 12.201.97.213 (Mon, 25 Sep 2006 19:31:47 GMT) NNTP-Posting-Date: Mon, 25 Sep 2006 19:31:47 GMT Date: Mon, 25 Sep 2006 19:31:47 GMT Xref: g2news2.google.com comp.lang.ada:6730 Date: 2006-09-25T19:31:47+00:00 List-Id: Alex R. Mosteo wrote: > > I had a concern over the efficiency of returning big (tagged) types, since I > like to store them in indefinite collections (a la Object'Class) instead of > storing pointers to them. It is said that, as tagged types are passed by > reference, they are always efficiently passed around. However, when you > are /returning/ and not calling, I had my doubts, so I have made this > simple testcase (see at bottom). This is a basic Ada concept. A function returns an object. A return statement gives the value of that object, so "return Borg;" means the returned object has the same value as Borg, but it is not the same object as Borg. Since the function returns a new object, it must create a copy. If the object is immediately assigned to a variable, an intermediate copy may be optimized away in some cases. You may want to compare assigning Borg to assigning a function call. Note that Borg is not a constant. That may affect the amount of optimization that is done. You seem to expect the function to return an alias. In Ada, if that's what you want, you have to explicitly return an alias. > So, what do you think? Is there some error in my reasoning or testbed? I think so. The real questions should be, what are the timing (or storage; it's not clear if you're discussing time or space efficiency) requirements for this application? Does the clearest implementation (returning an object) meet those requirements? If not, is complicating the code to return aliases the only way to meet them? If not, does one of the other ways have less of an effect on clarity? -- Jeff Carter "Don't knock masturbation. It's sex with someone I love." Annie Hall 45