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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4608b6f4718e680f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.223.40 with SMTP id qr8mr2184342pbc.0.1336550848935; Wed, 09 May 2012 01:07:28 -0700 (PDT) Path: pr3ni5405pbb.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: ytomino Newsgroups: comp.lang.ada Subject: Re: Problem in "X (1).Re := X (1).Re + 1" Date: Wed, 9 May 2012 01:05:50 -0700 (PDT) Organization: http://groups.google.com Message-ID: <15071427.1562.1336550750742.JavaMail.geo-discussion-forums@pbcia3> References: <13177506.38.1336222539273.JavaMail.geo-discussion-forums@pbtg6> <21452734.731.1336405064187.JavaMail.geo-discussion-forums@ynbv35> <5749033.1275.1336416838264.JavaMail.geo-discussion-forums@pbchd7> <10294366.7.1336426132700.JavaMail.geo-discussion-forums@yngg23> NNTP-Posting-Host: 118.8.128.51 Mime-Version: 1.0 X-Trace: posting.google.com 1336550848 21809 127.0.0.1 (9 May 2012 08:07:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 9 May 2012 08:07:28 +0000 (UTC) In-Reply-To: <10294366.7.1336426132700.JavaMail.geo-discussion-forums@yngg23> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=118.8.128.51; posting-account=Mi71UQoAAACnFhXo1NVxPlurinchtkIj User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Date: 2012-05-09T01:05:50-07:00 List-Id: On Tuesday, May 8, 2012 6:28:52 AM UTC+9, Adam Beneschan wrote: > > OK, I think I figured out what you were talking about. Sorry, but your > original post seemed to use a few words (like "implemented by > reference-counting") and expect that readers would fill in the rest of the > details. Unfortunately, I'm not a mind-reader, so it took me a lot of effort > to figure it out. Maybe others here are better mind-readers than I am. > I don't know. Uh... I'm sorry your time. > But I'm guessing that you're referring to an implementation where, when > a copy of an element is made, the implementation doesn't make a copy > immediately, but rather waits until somebody tries to modify either the > original or the copy and *then* splits off a copy. So in your example: > > X(1).Re := X(1).Re + 1.0; > > you're assuming that X(1) was earlier created as a copy of something else--or > that something else was created as a copy of X(1). The main ways I can see > that this could be done are by using the Copy or Assign operations of > vectors, e.g. > > X := Copy(W); > X(1).Re := X(1).Re + 1.0; Yes. I had to write something that increases the reference counter of X happened before the subject line. My omission about this issue was very bad. > so that when X is created, it's done by creating references to all the > elements in W rather than by copying the elements of W; and then making a new > copy of an individual element when it needs to be modified. Of course, > it's silly to do this if the element type is Complex, since it's surely > easier to copy two floats than to implement all the overhead needed to deal > with references. But I can imagine that it might make sense if the element > type is ... um, more complex than Complex. Or a whole lot bigger. > I'm still dubious that it can work, though. Consider: > > X := V.Copy(W); -- (A) > Ref1 := V.Constant_Reference (W, 1); -- (B) > Ref2 := V.Constant_Reference (X, 1); -- (C) > X(1).Re := X(1).Re + 1.0; -- (D) > > If the Copy function did not create any new copies of elements, then > Ref1.Element and Ref2.Element will end up being accesses to the same element, > after (C) is performed. If the new copy of the element is not created until > Reference is evaluated by the left side of statement (D), the result is that > either Ref2.Element (or possibly Ref1.Element) will be pointing at the wrong > thing. I was searching a way for controlling eval-order, when writing my first post. I thought the function having "aliased in out" should be called earlier than the function having "aliased in". But it was too simplistic. Your example awoke me to that it can save the result of Constant_Reference. Surely, it's the problem of *my* implementation. > So it looks to me like the method you suggest shouldn't be allowed, even > in your own container, since it would make it impossible to implement > Constant_Reference correctly. I still don't think it's impossible. How about inserting the copy-on-write code into Constant_Reference? > My caveat still applies, though; this involves issues that I'm not yet > completely familiar with, so it's possible that I made a serious error. > I'm hoping someone will come to my rescue if I did ... :) You at least seem more familiar with this than me. :)