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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3a7c118fd2cc64f9 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: A hole in Ada type safety Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <87oc3odtci.fsf@mid.deneb.enyo.de> <87tydfbtp3.fsf@mid.deneb.enyo.de> <87d3k2u36e.fsf@mid.deneb.enyo.de> <877ha2op0n.fsf@mid.deneb.enyo.de> <87oc3en898.fsf@mid.deneb.enyo.de> Date: Sun, 8 May 2011 10:08:13 +0200 Message-ID: <1mwaabp60tuqi$.1cbqxk0do4ic$.dlg@40tude.net> NNTP-Posting-Date: 08 May 2011 10:08:13 CEST NNTP-Posting-Host: ab163fca.newsspool2.arcor-online.net X-Trace: DXC=gFMLDL3KjbNE4ZB2flKORAA9EHlD;3YcB4Fo<]lROoRA8kF On Sat, 07 May 2011 11:57:07 +0200, Florian Weimer wrote: > * Dmitry A. Kazakov: > >> On Sat, 07 May 2011 11:09:44 +0200, Florian Weimer wrote: >> >>> As usual, there is a trade-off between flexibility and overhead: if >>> the reference counters are kept separate, it is possible to >>> implement weak pointers and safe references to sub-components. >> >> Interesting. Do you have a certain schema in mind, how to this? > > The shared pointers in C++ and Boost implement this. Andrei > Alexandrescu's Modern C++ Design contains a short overview of > implementation choices (but does not cover weak pointers). > > GCC's implementation of std::share_ptr uses separate pointers to > objects and their reference counts. The reference counts contain two > counters, for strong and weak references. The actual object is > dealloated when the strong count reaches zero. The reference counts > are deallocated when the strong and weak counts reach zero. I mean a schema which could be usable for Ada. I see many problems, apart from tasking. If you want to refer components, you need to add the parent's count to the component's count in order to prevent its zeroing. When you create a reference you have to check if the counts already exist somewhere. Since nothing is allocated in the object, where get that information from? IMO weak references are quite useless if do not support notifications (when the last strong reference is removed). I.e. you need a list of weak reference holders. Maintaining such lists is a problem. It is more than count, it can be changed during notifications etc. One possible approach could be a storage pool maintaining allocating and maintaining counts for all object allocated there. It won't work for components, though. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de