From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Comprehending subpools Date: Thu, 14 Jun 2018 16:21:59 -0500 Organization: JSA Research & Innovation Message-ID: References: Injection-Date: Thu, 14 Jun 2018 21:22:00 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="27207"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:53107 Date: 2018-06-14T16:21:59-05:00 List-Id: >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.