Path: utzoo!attcan!uunet!midway!uwvax!sevenlayer.cs.wisc.edu!bothner From: bothner@sevenlayer.cs.wisc.edu (Per Bothner) Newsgroups: comp.lang.c++ Subject: Re: A Parameterized Class for Semi-automatic Memory Management Message-ID: <11372@spool.cs.wisc.edu> Date: 27 Sep 90 20:57:06 GMT References: <11329@spool.cs.wisc.edu> <7050031@hpcupt1.HP.COM> Sender: news@spool.cs.wisc.edu Reply-To: bothner@sevenlayer.cs.wisc.edu (Per Bothner) Organization: University of Wisconsin--Madison Lines: 37 >In your scheme, is shared ownership prohibited? If an object is owned, it is not supposed to be shared. It is possible to "lend" an object, with the understanding it must not be destroyed. But the whole point of the "owned" template class is that it specifies that an object is NOT shared. >If so, do you think this is too much a restriction? In general, yes, but the scheme is intended as a discipline, not a universal solution. Note that "owned" objects can coexist with other storage management schemes, such as garbage collection. An example: Variable-sized objects (e.g. arbitrary-precision Integers) in libg++ are all implicitly "owned", since libg++ copies objects as needed to guarantee that only one reference exists to each object. This is done semi-automatically, and copying/deleting happens very much like in my "owned" scheme. But the problem is that *all* Integers in libg++ are "owned": if you want to share two Integers (and suppress the automatic copying), you have to to muck about with casts and the low-level representation. It would be nice to have two kind of Integer class: one whose objects are owned, and another class whose objects can be shared (at the cost of requiring the programmer (or a garbage collector) to explicitly reclaim storage). The "owned" scheme is a way to abstract away this distinction: The library designer need just write the "shared" version of (say) Integer, and then to get the "owned" semantics (as in the current libg++) one just declares one's variables as "owned". A similar scheme for reference counting (e.g. reference_counted) would also be worth exploring, but that is another discussion. -- --Per Bothner bothner@cs.wisc.edu Computer Sciences Dept, U. of Wisconsin-Madison