comp.lang.ada
 help / color / mirror / Atom feed
From: Markus E Leypold <development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de>
Subject: Re: Amount of copying on returned constant objects
Date: Wed, 20 Jun 2007 03:31:19 +0200
Date: 2007-06-20T03:31:19+02:00	[thread overview]
Message-ID: <t9tzt3o1i0.fsf@hod.lan.m-e-leypold.de> (raw)
In-Reply-To: f59huq$55d$1@jacob-sparre.dk


> "Alex R. Mosteo" <devnull@mailinator.com> wrote in message
> news:5dpp8pF35116bU1@mid.individual.net...
>> Randy Brukardt wrote:
> ...
>> > What really would help would be a way for the container to know when the
>> > access was destroyed, but there isn't any obvious way to do that in Ada.
>>
>> I guess then that some reference counting companion type (or maybe making
>> Cursors tagged and more heavyweight) was discarded because the distributed
>> overhead?
>
> Cursors can be tagged if the implementation so choses, but that doesn't have
> an effect on the element access problem. For that you need something that
> allows direct dereferencing, and in Ada as it stands, that can only be an
> access type.

I wonder wether you can't hide the dereferencing. I had a similar
Problem some time ago when implementing a cache of (rather large)
objects, but didn't want to make copies of every object when iterating
over them (i.e. for sorting or filtering purposes). My solution was to
have a generic function "Iterate" which is instantiated with the cache
and a function "operation" that will be doing the work on the
elemens. The elements are passed to operation (in this case) as 'in'
parameters, so 'operation' will not be able to change the elements,
only read them.

I wonder wether container implementations couldn't use a similar
trick: Instead of dereferencing a "do_with" generic would take an
operation as a parameter to which in turn the elements are passed
(control passes to do_with, do_with dereferences and passes elements
to operation).

This doesn't avoid the problem of cursors that become invalid. The
solution I see there would be to avoid cursors altogether and use
generic traversal and iteration functors like fold() for lists. This
way position is never made explicit and cannot be saved into a
variable.


>
> Having a companion type would work if it was impossible to separate
>the access from the reference counter. But there is no way in Ada to
>have a visible access type that cannot be assigned out of its
>surrounding wrapper.  (Which is why I said that Dmitry would say that
>redefinition of ".all" for a private type could solve the problem.)
>

What about a tagged type that is the abstraction of a storage cell
with method like Get(), Set() and Pass_Me_the_Data()? 

I've not thought much about the details, but that should cover the
most common use cases.

Regards -- Markus







  reply	other threads:[~2007-06-20  1:31 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
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 [this message]
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