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,eca91508b02e7e97 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Newsgroups: comp.lang.ada Subject: Re: Amount of copying on returned constant objects References: <5dfsfnF1qav8bU1@mid.individual.net> <46730bf5$0$23134$9b4e6d93@newsspool1.arcor-online.net> <5dntd6F35jc57U1@mid.individual.net> <4676C27D.2050608@obry.net> <5dpp8pF35116bU1@mid.individual.net> From: Markus E Leypold Organization: N/A Date: Wed, 20 Jun 2007 03:31:19 +0200 Message-ID: User-Agent: Some cool user agent (SCUG) Cancel-Lock: sha1:4FICyM7+aFoxbP53w58NLxWgIR0= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 88.72.214.6 X-Trace: news.arcor-ip.de 1182302490 88.72.214.6 (20 Jun 2007 03:21:30 +0200) X-Complaints-To: abuse@arcor-ip.de Path: g2news1.google.com!news4.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor-ip.de!news.arcor-ip.de!not-for-mail Xref: g2news1.google.com comp.lang.ada:16250 Date: 2007-06-20T03:31:19+02:00 List-Id: > "Alex R. Mosteo" 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