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!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Comprehending subpools Date: Sat, 16 Jun 2018 09:36:19 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: CvkHMVp693S8Z+lk11jyqg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 X-Notice: Filtered by postfilter v. 0.8.3 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:53133 Date: 2018-06-16T09:36:19+02:00 List-Id: On 2018-06-16 00:15, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:pfvp1k$ph4$1@gioia.aioe.org... >> On 2018-06-14 23:21, Randy Brukardt wrote: >> >>> 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. >> >> I think the questions rather were: >> >> 1. What is so special about arena or a mark-and-release pool that it >> cannot be handled by a user-defined pool in Ada 95? > > No pool that does block deallocation (not using Unchecked_Deallocation) can > work properly with controlled objects. Yes, but that was the second question. The first was if arena can be implemented in Ada 95. It can. >> 2. Arena is inherently unsafe whatever implementation used. So all talk >> about "safety" does not make much sense. > > "Safety" in this case is related to properly handling controlled types. With > that, one can construct properly working strong and weak references and > other safe memory management structures that will work on essentially any > Ada objects. Without it, you have no chance of any safe memory management. > > The basic idea is that one manages the "strong" references to an arena (such > as the reference to the root of a tree), and when they are all gone, one can > safety destroy the arena. The weak references aren't managed for that > purpose, but don't become erroneous when the arena is destroyed, but rather > just get (effectively) nulled out. In effect it means that all references to the objects also hold a reference to the pool. It is no problem to implement with an Ada 95 pool. > One could implement the containers this way, such that when a container is > destroyed, that the entire arena of nodes is immediately reclaimed. (There's > no legal references into the container at that point.) > > In any case, a subpool by itself doesn't provide any safety; it's just a > building block to be used to provide such safety. All of the other things > needed to build such abstractions already existed in Ada, the only thing > missing was an ability to finalize all of the objects in an arena (subpool) > at once. Right, it is so special case that I join OP wondering why this was paid any attention at all. Normally the schema is reverse, the objects must go when the arena goes, if any safety could be added, then a linked list of objects to finalize [prematurely, BTW] as it is done in other cases. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de