comp.lang.ada
 help / color / mirror / Atom feed
From: "Alejandro R. Mosteo" <alejandro@mosteo.com>
Subject: References vs access types
Date: Fri, 31 May 2019 17:44:34 +0200
Date: 2019-05-31T17:44:34+02:00	[thread overview]
Message-ID: <qcri52$1tn$1@dont-email.me> (raw)

Sorry if I asked something similar in the past. I have a foggy memory of 
having wanted to do so. I have also checked some old threads that 
tangentially touch my question but without direct explanation.

So, part of the point of reference types is to be able to return an item 
"by reference" without being able to store the pointer:

    type Item;
    type Item_Access is access Item;

    type Reference (Ptr : access Item) is limited null record;

    function Get (...) return Reference; -- (1)

In Gem #107 this is said as advantageous against, for example,

    function Get (...) return Item_Access; -- (2)

because "access discriminants are unchangeable. The discriminant also 
cannot be copied to a variable [like Item_Access]" [1].

Now, without thinking much about it, while fighting old bugs, I have 
sometimes replaced a problematic Reference with

    function Get (...) return access Item; -- (3)

And here comes the question: besides losing the ability to use aspects on 
the Reference type, or using it for some fancy refcounting, does (3) give 
the same safeties wrt to copying as (1)? Are there any other hidden traps 
in (3) (assuming the pointee thread-safety/lifetime is properly managed)?

Or, put it another way, is (1) always preferable? Or may (3) suffice for 
simple uses?

Thanks,
Álex.

[1] 
https://www.adacore.com/gems/gem-107-preventing-deallocation-for-reference-counted-types/


             reply	other threads:[~2019-05-31 15:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31 15:44 Alejandro R. Mosteo [this message]
2019-05-31 16:55 ` References vs access types Dmitry A. Kazakov
2019-05-31 23:55   ` AdaMagica
2019-05-31 23:56     ` AdaMagica
2019-05-31 21:33 ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox