From: Natasha Kerensikova <lithiumcat@instinctive.eu>
Subject: Re: How to declare a generic formal type "covered" by another?
Date: Fri, 2 May 2014 08:17:40 +0000 (UTC)
Date: 2014-05-02T08:17:40+00:00 [thread overview]
Message-ID: <slrnlm6l53.i0l.lithiumcat@nat.rebma.instinctive.eu> (raw)
In-Reply-To: 21e0e1f0-3fe4-4c5a-8e01-21691a0207f4@googlegroups.com
On 2014-05-02, AdaMagica <christ-usch.grein@t-online.de> wrote:
>> Most smart-pointer packages expose the access type; see, for example,
>>
>> http://www.oopweb.com/Ada/Documents/AdaLinux/Volume/18.html
>> http://www.adacore.com/adaanswers/gems/gem-97-reference-counting-in-ada-part-1/
>
> But exposing the access type is bad since pointes may easily outlive the object they point to.
>
> Let Get return the access value of the smart pointer P and let P be the only pointer to the object accessed. Let Q be another smart pointer.
>
> declare
> Obj: access Client_Data'Class := Get (P);
> begin
> My_Data (Obj.all).I := 2012; -- No problem.
> P := Q; -- Frees the original object,
> -- because the reference count
> -- is zero after this operation.
> My_Data (Obj.all).I := 95; -- Oops - writing freed memory!
> end;
>
> See also:
>
> http://www.adacore.com/adaanswers/gems/gem-107-preventing-deallocation-for-reference-counted-types/
I have already read that gem, and used that mechanism in my generic
package.
Your text here show how exposing access *values* is bad, which I already
guessed, but it says nothing about the risks of exposing only the
internal access *type*, and involving access values only as input from
client, never to be seen again.
The only risk I identified in such a case is if the client stores an
access value it has provided to the reference-counting and subsequently
uses it.
Are there any other risk? Is there a way to mitigate them?
next prev parent reply other threads:[~2014-05-02 8:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-01 6:54 How to declare a generic formal type "covered" by another? Natasha Kerensikova
2014-05-01 7:09 ` J-P. Rosen
2014-05-01 7:33 ` Natasha Kerensikova
2014-05-01 13:35 ` J-P. Rosen
2014-05-01 17:56 ` Natasha Kerensikova
2014-05-01 20:59 ` Jeffrey Carter
2014-05-02 7:58 ` AdaMagica
2014-05-02 8:17 ` Natasha Kerensikova [this message]
2014-05-02 15:12 ` Jeffrey Carter
2014-05-02 15:33 ` Dmitry A. Kazakov
2014-05-02 16:00 ` AdaMagica
2014-05-01 9:30 ` Georg Bauhaus
2014-05-01 9:32 ` Georg Bauhaus
2014-05-01 9:33 ` Georg Bauhaus
2014-05-01 16:34 ` Georg Bauhaus
2014-05-01 18:11 ` Natasha Kerensikova
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox