Owned members

Robert Jacques sandford at jhu.edu
Sat Dec 25 11:45:59 PST 2010


On Sat, 25 Dec 2010 15:18:07 -0700, Alex Khmara <alex.khmara at gmail.com>  
wrote:

> On Sat, 25 Dec 2010 19:18:43 -0000, Robert Jacques <sandford at jhu.edu>  
> wrote:
>
>> This @owned is very similar to previous 'scope' proposals (and oddly  
>> dissimilar to previous owned proposals). To answer your question, under  
>> previous proposals the scope keyword would allow you to declare that a  
>> variable doesn't escape the current scope. So you could define external  
>> functions that would take a 'scope int[]' and be guaranteed that it  
>> wouldn't escape. (returning scoped values has to obey certain  
>> restrictions)
>>
>> The previous 'owned' proposals are a bit more general. Owned types  
>> allow you parameterize a type on a variable, which sounds complex, but  
>> what it means in terms of the runtime, is that all objects in the same  
>> ownership group shared the same monitor. The big advantage is that  
>> inside a synchronized method you don't have to synchronize other  
>> 'owned' objects of the same type. It also makes this like unique a lot  
>> more viable, since you can now define trees, etc.
>
> Ok, I'll try to find previous proposals about 'scope' - now I cannot  
> understand
> how you can prevent external function from, e.g., saving owned object or  
> array (i.e. references)
> in global variable, if it's at all possible to pass owned variables into  
> external functions.

Well, think about pure. A pure function can call other pure functions,  
because those functions declare that they obey the rules of pure (i.e. no  
globals, etc). Scope variables can be passed to functions taking scoped  
parameters because those functions declare that they'll obey the rules of  
scope (i.e. they won't squirrel away references to it, etc).


More information about the Digitalmars-d mailing list