From: ytomino <aghia05@gmail.com>
Subject: Re: Problem in "X (1).Re := X (1).Re + 1"
Date: Mon, 7 May 2012 11:53:58 -0700 (PDT)
Date: 2012-05-07T11:53:58-07:00 [thread overview]
Message-ID: <5749033.1275.1336416838264.JavaMail.geo-discussion-forums@pbchd7> (raw)
In-Reply-To: <21452734.731.1336405064187.JavaMail.geo-discussion-forums@ynbv35>
On Tuesday, May 8, 2012 12:37:44 AM UTC+9, Adam Beneschan wrote:
>
> No. But if you change the 1 to 1.0 then I think it will be OK.
Oops!
1.0 is correct.
> I'm not yet really familiar with the ins and outs of user-defined references
> and user-defined indexing. But my guess is that the phrase in A.18.2(147.17)
> that says "Reference returns an object whose discriminant is an access value
> that designates the element designated by Position" means that Reference
> can't return an object whose discriminant designates a *copy* of the element.
> If I understand your question correctly, this means that the scenario you're
> concerned about can't happen.
Imagine an implementation of an reference-counted container.
Probably, it's like below:
function Reference (Container : Vector; Position : Cursor) return Ref_Type is
begin
-- if data is shared, do copy-on-write to prepare for change
-- (memory management and exclusive control is omitted in this pseudo-code)
if Container.Data_Block.Ref_Count > 1 then
Container.Data_Block.Ref_Count := Container.Data_Block.Ref_Count - 1;
Container.Data_Block := new Data_Block_Type'(
Length => Container.Data_Block.Length,
Elements => (1 .. Length => Container.Data_Block.Elements (1 .. Length)),
Ref_Count => 1);
end if;
-- return access value designated by Position
return (Element => Container.Data_Block.Elements (To_Index (Cursor))'Access);
end Reference;
And, similar copy-on-write is inserted into Replace_Element and Update_Element.
In this container, Reference copies its elements as your saying. But the container comes to own copied elements, and Reference returns an access value that designates the element in same area. I hope that this is allowed for effective implementations.
Besides, if this is disallowed in Ada.Containers.Vectors, please assume my original container.
Surely you don't think that all reference-counted containers written by user are forbidden to implement user-defined indexing.
next prev parent reply other threads:[~2012-05-07 18:55 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-05 12:55 Problem in "X (1).Re := X (1).Re + 1" ytomino
2012-05-07 15:37 ` Adam Beneschan
2012-05-07 18:53 ` ytomino [this message]
2012-05-07 21:28 ` Adam Beneschan
2012-05-08 1:14 ` Randy Brukardt
2012-05-08 17:14 ` Adam Beneschan
2012-05-08 22:29 ` Randy Brukardt
2012-05-09 8:41 ` ytomino
2012-05-10 0:52 ` Randy Brukardt
2012-05-10 5:23 ` ytomino
2012-05-09 9:29 ` ytomino
2012-05-10 0:58 ` Randy Brukardt
2012-05-10 4:26 ` ytomino
2012-05-15 6:09 ` Randy Brukardt
2012-05-15 20:17 ` ytomino
2012-05-16 0:01 ` Randy Brukardt
2012-05-15 22:12 ` Simon Wright
2012-05-16 7:14 ` Dmitry A. Kazakov
2012-05-09 8:05 ` ytomino
2012-05-09 11:03 ` ytomino
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox