From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: Efficiency of returning big objects
Date: Mon, 25 Sep 2006 19:31:47 GMT
Date: 2006-09-25T19:31:47+00:00 [thread overview]
Message-ID: <D8WRg.205891$1i1.167542@attbi_s72> (raw)
In-Reply-To: <4npvh0FbgbuhU1@individual.net>
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
next prev parent reply other threads:[~2006-09-25 19:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-25 12:14 Efficiency of returning big objects Alex R. Mosteo
2006-09-25 13:09 ` Dmitry A. Kazakov
2006-09-25 13:51 ` Alex R. Mosteo
2006-09-25 15:24 ` Georg Bauhaus
2006-09-25 16:41 ` Alex R. Mosteo
2006-09-25 19:31 ` Jeffrey R. Carter [this message]
2006-09-26 7:45 ` Alex R. Mosteo
2006-09-26 0:33 ` Adam Beneschan
2006-09-26 7:43 ` Alex R. Mosteo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox