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: <11373@spool.cs.wisc.edu> Date: 27 Sep 90 22:07:27 GMT References: <11329@spool.cs.wisc.edu> <57692@microsoft.UUCP> Sender: news@spool.cs.wisc.edu Reply-To: bothner@sevenlayer.cs.wisc.edu (Per Bothner) Organization: University of Wisconsin--Madison Lines: 28 >On each parameter passed to a method, or returned from a method, the class >producer and class consumer must agree on whether ownership should be passed >for that parameter or not. Good point - but they have to do that anyway. My proposal does have the advantage that the compiler enforces agreement. It may be possible to extend the scheme to automatically convert between owned and shared references: - If an owned pointer is initialized *from* a shared pointer, the initializer should allocate and contruct a copy. - An owned pointer can be coerced *to* a shared pointer by just extracting the stored (plain) pointer. One problem: there are now two kinds of initializtion of owned variables: From (a pointer to) a shared object (yielding ownership of a copy), and from (a pointer to) an owned object (transferring ownership). The former could be expressed by owned(T*) and the latter by owned(T&). I don't know how error-prone this would be. It may also be possible to generate better code if knowledge about "owned" is built into the compiler. -- --Per Bothner bothner@cs.wisc.edu Computer Sciences Dept, U. of Wisconsin-Madison