comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Comprehending subpools
Date: Thu, 14 Jun 2018 16:21:59 -0500
Date: 2018-06-14T16:21:59-05:00	[thread overview]
Message-ID: <pfum9o$qi7$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: b21095b9-c373-473c-812d-8713ce86992b@googlegroups.com

>Alright, so maybe this is intended for the case where you can control the
>entire scope, and not have to worry about passing them around.  But in
>those cases, can't you just declare a new access type and use 'Storage_Size
>(or a normal storage pool) to give you exactly that?

The use case is situations when you have separable data structures that it 
only makes sense to treat as a whole. Think of an expression tree in a 
compiler. There are a lot of inter-structure links, so a reference counting 
scheme for every pointer doesn't work. Rather, you can use a subpool and 
only reference count the references to the entire tree. When that goes to 
zero, you use the subpool to clobber the entire structure. Alternatively, 
you might have weak references to the tree, that automatically get nulled 
when the tree is clobbered.

You can't use separate access types in cases like this, since there's lots 
of shared code that needs to take pointers to these trees. And you want to 
clobber the whole structure at once, as that reduces the possibility of 
dangling pointers.

Tucker originally had various weak and strong references with the subpool 
proposal, but those were massively complex and can easily be constructed out 
of existing Ada concepts. So the subpool is a tool, but it's expected to be 
used with programmer constructed strong and weak references - by itself, it 
only really provides one thing: the ability to finalize a group of objects 
together. (The one thing that you can't do without it.)

It *is* a niche need; personally, I think using tree containers to represent 
an expression tree would be a better solution to the problem given above. 
Those too can have dangling pointers, but only if you insist on an 
implementation that puts performance above safety. (Unfortunately, many 
users do exactly that.) It's relatively easy to detect all dangling cursors 
for the unbounded containers (the requirement for the packages to be Pure 
prevents such detection for the bounded containers, although the usual 
implementation of a bounded container  means that such cursors still point 
at *something*, it's just not what you expect).

In any case, subpools precedes the tree containers, so that wasn't an option 
then. For me, I'd try to avoid ever writing an access type and use the 
containers instead (you can get dangling detection for free, and many 
operations -- like iteration and lookup -- never need a cursor in the first 
place).

                                          Randy.



  reply	other threads:[~2018-06-14 21:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-14 13:48 Comprehending subpools sbelmont700
2018-06-14 21:21 ` Randy Brukardt [this message]
2018-06-15  7:15   ` Dmitry A. Kazakov
2018-06-15 22:15     ` Randy Brukardt
2018-06-16  7:36       ` Dmitry A. Kazakov
2018-06-19  0:32       ` sbelmont700
2018-06-29 19:57         ` Randy Brukardt
2018-06-29 22:42           ` Shark8
replies disabled

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