From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: How to declare a generic formal type "covered" by another?
Date: Fri, 2 May 2014 00:58:49 -0700 (PDT)
Date: 2014-05-02T00:58:49-07:00 [thread overview]
Message-ID: <21e0e1f0-3fe4-4c5a-8e01-21691a0207f4@googlegroups.com> (raw)
In-Reply-To: <ljucjn$in$1@dont-email.me>
> 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/
next prev parent reply other threads:[~2014-05-02 7:58 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 [this message]
2014-05-02 8:17 ` Natasha Kerensikova
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