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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3498dd887729ed19 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Garbage Collection in Ada Date: 1996/11/03 Message-ID: #1/1 X-Deja-AN: 194253094 references: <01bbc6a3$4cf03480$829d6482@joy.ericsson.se> content-type: text/plain; charset=ISO-8859-1 organization: Estormza Software mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-11-03T00:00:00+00:00 List-Id: In article , mg@harp.camb.inmet.com (Mitch Gart) wrote: >: package Collected is > >(snip) > >This suffers from several problems: > >- If you provide a function to do allocations, > > function Allocate_Obj return Handle; > > and users use this function, things work well, but if a user calls > "new Object" directly things don't work at all. > >- Obj1 := Obj2; doesn't work because the reference count value is > copied. If Obj2's count is 3 before the assignment, after the assignment > Obj1's count is also 3 which is probably wrong. Actually, Mitch's example points out what I feel is an omission in the langauge: the ability to overload the access object deference operator "all". (Yeah, yeah, I already _know_ it's not an operator. My point is that I want it to be.) I like having the control of finalization of objects, but I would also like the ability to finalize an access object, so that when its lifetime ends I can decrement a reference count. The previous examples in this thread do that, but there's a large syntactic difference between manipulating an Ada access object and those that aren't access objects. I don't want to have to do any work to get at the "real" access object component of a (controlled) handle object. I want to be able to define a type that's a subtype of Finalization.Controlled, and define primitive operations for it so that it's syntactically identical to an access type. I don't want the user of my "access type" to have to do anything different than he would have do to when manipulating a "normal" access type. So I want to be able to do this type T is ...; type TA is private; function "new" (O : T) return TA; function "all" (O : TA) return T; private type T_Rep is record O : T; Count : Natural; end record; type TA_Rep is access T_Rep; type TA is new Finalization.Controlled with record Rep : TA_Rep; end record; ... O : TA := ...; begin ... O.all ... If this package were generic (with T as its generic formal type), then I suppose this access type would be very reusable. Whatever else you might think about C++, you have to admit that letting the programmer define operators for his class-types, to make them look like built-in types, is very nice. Language designers: any reason why overloading "all" would be too hard? -------------------------------------------------------------------- Matthew Heaney Software Development Consultant mheaney@ni.net (818) 985-1271