From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: Amount of copying on returned constant objects
Date: Mon, 18 Jun 2007 20:23:49 +0300
Date: 2007-06-18T20:23:49+03:00 [thread overview]
Message-ID: <5dntd6F35jc57U1@mid.individual.net> (raw)
In-Reply-To: 46730bf5$0$23134$9b4e6d93@newsspool1.arcor-online.net
Georg Bauhaus wrote:
> Alex R. Mosteo wrote:
>>
>>
>> I wonder however about results of functions, that are not modified.
>>
>> ... In C++ I could use constant references. Now, I wonder if
>>
>> a) is there something in the ARM that prevents an equivalent transparent
>> optimization in the Ada side (returning the reference when it is detected
>> that the returned object is not modified)?
>
> OTOH, I might want a constant copy because the object in the
> container is going to be modified... Can a compiler detect this?
I don't think it can, at least easily. I guess that if you're keeping a
copy, constant or not, the optimization opportunity is lost. But what about
short-lived objects, like...
if Container.Element ("key").Is_Nice then -- Container for some tagged type
...
end if;
This is the kind of copies that I see interesting to optimize away. I don't
know enough about compilers to say if it is reasonable to expect one to
detect this situation or not.
If not, one possibility would be to have
function Element (Key : Key_Type) return Element_Type;
and
type Constant_Access is access constant Element_Type;
function Element (Key : Key_Type) return Constant_Access;
but I'm not sure about the amount of ambiguities one would get in that case.
In any case this does not exist in the standard 05 containers.
next prev parent reply other threads:[~2007-06-18 17:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-15 16:19 Amount of copying on returned constant objects Alex R. Mosteo
2007-06-15 16:32 ` Ludovic Brenta
2007-06-18 17:26 ` Alex R. Mosteo
2007-06-19 10:22 ` Alex R. Mosteo
2007-06-15 22:03 ` Georg Bauhaus
2007-06-18 17:23 ` Alex R. Mosteo [this message]
2007-06-18 17:35 ` Pascal Obry
2007-06-18 18:04 ` Alex R. Mosteo
2007-06-18 20:25 ` Randy Brukardt
2007-06-19 8:26 ` Dmitry A. Kazakov
2007-06-19 10:24 ` Alex R. Mosteo
2007-06-19 21:33 ` Randy Brukardt
2007-06-20 1:31 ` Markus E Leypold
2007-06-20 6:25 ` Georg Bauhaus
2007-06-20 13:00 ` Markus E Leypold
2007-06-20 7:34 ` Dmitry A. Kazakov
2007-06-18 18:34 ` Georg Bauhaus
2007-06-16 6:48 ` Dmitry A. Kazakov
2007-06-18 17:14 ` 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