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!postnews.google.com!m7g2000cwm.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Efficiency of returning big objects Date: 25 Sep 2006 17:33:23 -0700 Organization: http://groups.google.com Message-ID: <1159230803.296443.27880@m7g2000cwm.googlegroups.com> References: <4npvh0FbgbuhU1@individual.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1159230808 26643 127.0.0.1 (26 Sep 2006 00:33:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 26 Sep 2006 00:33:28 +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: m7g2000cwm.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:6737 Date: 2006-09-25T17:33:23-07:00 List-Id: Alex R. Mosteo wrote: > Hello, > > I had a concern over the efficiency of returning big (tagged) types...... > Now, in C++ I would force this behavior explicitly returning references (I > guess this is the usual practice, but I'm not sure). In Ada, I have no idea > how to match this efficient behavior. > > So, what do you think? Is there some error in my reasoning or testbed? Is > this a particular shortcoming of this compiler (gnat gpl 2006), or I'm > overlooking something that makes this very non-trivial to implement? If I'm understanding you correctly, in your original program, you'd like it if Create simply returned a pointer to Borg, and then the parameter to Check used the pointer to Borg, and no copying would be done. But then the following program wouldn't work right. Note that according to the Ada rules, since the function Create is *not* return-by-reference, the Ada semantics indicate that the result of Create is an anonymous object (6.5(21)); therefore, Borg and Y are not supposed to denote the same object, and the rule about distinct access paths (6.2(12)) doesn't apply to the example below. I think that expecting a compiler to figure out what's going on, so that it wouldn't optimize the copy away in my example but *would* optimize it away in yours, may well be too much to ask. -- Adam with Ada.Calendar; use Ada.Calendar; with Ada.Text_Io; use Ada.Text_Io; procedure Ref is type Big_Thing is array (1 .. 64_000) of Character; type T is tagged record Dummy : Big_Thing := (others => 'c'); X : Integer := 0; end record; Borg : T; procedure Check (Y : T) is begin Borg.X := 1133; --- We can't let this modify Y!!! if Y.X /= 0 then raise Constraint_Error; end if; end Check; function Create return T is begin return Borg; end Create; Start : Time; Iters : Natural; begin -- Pass - how? Iters := 0; Start := Clock; while Clock - Start < 1.0 loop Check (Create); Iters := Iters + 1; end loop; Put_line ("Pass value:" & Natural'Image (Iters)); end Ref;