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: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.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> <1mwaabp60tuqi$.1cbqxk0do4ic$.dlg@40tude.net> <87oc3dtwaa.fsf@mid.deneb.enyo.de> Date: Sun, 8 May 2011 11:32:25 +0200 Message-ID: NNTP-Posting-Date: 08 May 2011 11:32:24 CEST NNTP-Posting-Host: c0dd62d0.newsspool1.arcor-online.net X-Trace: DXC=R4Fo<]lROoR1<`=YMgDjhg2^0\f^MK@8?9[6LHn;2LCV>[ On Sun, 08 May 2011 10:46:05 +0200, Florian Weimer wrote: > * Dmitry A. Kazakov: > >> 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. > > The component wouldn't have its own count. A reference to a component > would consist of a pointer to the component, combined with a pointer > to the reference counters for the outmost object. Then a built-in access-to-component type might be a better solution. It would eliminate a need for components to be aliased. Since the offset is statically known (or a function that calculates it is), it need not to be kept anywhere. But the actual problem is that references to components look useless if cannot be mixed with plain access to the component types. Ada does not have means for that. E.g. classes of access types. >> 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? > > You would only be able to create a reference from prefixes which > contain references at certain points. OK, but you need to create the first reference somehow. That is what an embedded count does, the object is kind of a reference to itself. If that is dropped, one have to find another mechanism for that. >> 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. > > I think they are supposed to be used for parent pointers in trees, for > instance, to avoid the cycle issue. Not so much for finalization. I rather use: parent-->child is a plain pointer, child-->parent is a strong reference. The most interesting cases for weak references are in the first line finalization notification. E.g. cached objects. They are referenced by weak reference by the cache monitor. When the object is finalized, the monitor synchronizes the object's actual state with the non-volatile memory etc. I think that the issue is too varying and complex to have it built-in. I would prefer if Ada provided mechanisms for implementation of such stuff at the library level. E.g. user-defined access types with primitive referencing, dereferencing, finalization operations. Classes of access types etc. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de