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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.102.34 with SMTP id fl2mr593468obb.16.1411489408586; Tue, 23 Sep 2014 09:23:28 -0700 (PDT) X-Received: by 10.182.73.193 with SMTP id n1mr8013obv.27.1411489408377; Tue, 23 Sep 2014 09:23:28 -0700 (PDT) Path: buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.glorb.com!h15no4858978igd.0!news-out.google.com!rp1ni1450igb.0!nntp.google.com!a13no2227275igq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 23 Sep 2014 09:23:28 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <024b1649-e056-4b7a-9072-7c7ef0c53f0b@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0809ce38-9205-4723-a7d6-189eca7ee724@googlegroups.com> Subject: Re: Trying to understand Ada.Finalization.Controlled assignment mechanics. From: Adam Beneschan Injection-Date: Tue, 23 Sep 2014 16:23:28 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.dca.giganews.com comp.lang.ada:189106 Date: 2014-09-23T09:23:28-07:00 List-Id: On Tuesday, September 23, 2014 9:08:39 AM UTC-7, Jeremiah wrote: > Am I understanding that correctly? If so, then this would explain what I= am seeing as I am setting the target to null and not nulling the previous = object (which is the reverse of what I previously understood). >=20 > TLDR version (barring the actual complexities you noted above): > I previously thought: > A :=3D B > Finalize(A) > copying B into A > Adjust(B) >=20 > But in reality it is closer to: > Finalize(A) > copying B into A > Adjust(A) >=20 > Again, not taking into account the complexities of FRO's and Anonymous Ob= jects. Yes, you've got it right. If you say "A :=3D B;", B is not modified at all= . B could be a constant, in fact, and it could be located in read-only mem= ory. (An Adjust(B) call would try to modify B.) Although Adjust can be used for a number of things, one of the most common = cases is to make a copy of pointed-to data. Say the record type has a fiel= d Data that is an access type to some array. Say you don't want two record= s of the same type pointing to the exact same array, but instead you want t= o make a copy of the array when you create a new object of the type. That'= s where Adjust comes in. When you say A :=3D B, the program will copy B into A, which means they tem= porarily have an access (pointer) to the same data. The Adjust procedure w= ould then allocate a new array, make a copy of it, and leave A's Data point= ing to the new array. (It doesn't modify B's data pointer at all, and you = wouldn't want to, even if B weren't constant.) The Finalize procedure woul= d deallocate the array. Assuming that the record type is private so that o= utside packages can't modify the Data pointer directly, this will ensure th= at each record points to its own copy of the array, and that there will not= be any dangling pointers to deallocated arrays, unless the outside code do= es something underhanded like Unchecked_Conversion or something. -- Adam