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,5653f0bd43045b85 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: garbage collection Date: 1999/08/20 Message-ID: <37be0c85@news1.us.ibm.net>#1/1 X-Deja-AN: 515348403 Content-transfer-encoding: 7bit References: X-Trace: 21 Aug 1999 02:18:45 GMT, 129.37.213.181 Organization: Global Network Services - Remote Access Mail & News Services X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset="US-ASCII" Mime-version: 1.0 Newsgroups: comp.lang.ada X-Complaints-To: postmaster@ibm.net Date: 1999-08-20T00:00:00+00:00 List-Id: In article , Keith Thompson wrote: > Specifying the 'Storage_Pool attribute is a very powerful and > under-used feature, IMHO. The biggest obstacle to its use, I suspect, > is the need to implement the Storage_Pool operations. One thing I miss is not having a set of nameable, pre-defined storage pools. You have that in GNAT, but it's not really portable because of certain low-level calls (to a C routine called "_gnat__allocate", or something like that). > If System.Storage_Pools also provided routines for dereferencing > access values (perhaps one each for reading and writing), and perhaps > also for initialization and finalization of access objects, it would > be even more powerful. I haven't entirely thought this through, so it > may be a bad idea for some reason. That's one nice thing about C++. You can implement a pointer abstraction that has a syntax identical to a built-in pointer. In Ada95, you have to implement a "handle" type that provides a dereference operator: type T (<>) is limited private; type T_Access is access all T; type T_Handle is private; function "+" (Handle : T_Handle) return T_Access; All the primitive operations of T take access parameters, since we're always dealing with pointers to T: procedure Op (O : access T); function Get_Attribute (O : access T) return Attr_T; You also have constructor(s) that return a handle object: function New_T return T_Handle; -- not T_Access All the actual garbage collection is associated with T_Handle, since there's no way to do that with the access type T_Access directly. (Which is how Ada95 differs from C++.) I use this technique to implement reference-counting for on-the-heap abstractions, so that when the count drops to zero the memory is automatically reclaimed. See the patterns archives for lots of examples. The only trap door in this scheme is that there's no way to prevent the client from manipulating the access object directly, say, by making a copy. It has to be understood by users that that is something you never do with a handle-based abstraction. It would be swell if the language were amended to make access types limited; this would prevent any problems engendered by accidental copying of access objects. -- Matt It is impossible to feel great confidence in a negative theory which has always rested its main support on the weak points of its opponent. Joseph Needham, "A Mechanistic Criticism of Vitalism"