December 11, 2012
On 12/11/12 9:37 AM, Dan wrote:
> On Tuesday, 11 December 2012 at 13:01:44 UTC, Andrei Alexandrescu wrote:
>> Walter and I discussed that it should be possible to automate the
>> dupIfNeeded() (I call it ensureUnique()) calls like this:
>>
>> * If a method is const or immutable, leave as is
>> * For all other methods, insert a ensureUnique() automatically in the
>> prolog code
>>
>> For this to work, the state must be private and all primitives must be
>> implemented via methods (as opposed to free functions).
>>
>
> This sounds good. But ensureUnique replacing dupIfNeeded really does two
> things - (1) determine if a copy is necessary (i.e. has a copy already
> been done) and (2) actually do the copy when necessary. What would it
> use to do the generic copy and what type of copy would it be (1 level
> deep (e.g. dup all fields of typeof(this)) or dup recursively deep)?

That would be left to the user in the form of a .dup primitive. Automation is only concerned with maintaining the refcount and making sure duplication is invoked when needed.

> I don't think the compiler can choose which of these two is desired by
> the user. This would then call for some form of field copy mechanism
> similar to postblit, likely defined by user.
>
> I think giving the struct designer a simpler way to do COW sounds very
> useful. Would love to read a DIP or notes on it. IMHO there are many
> coding use cases for me where even thinking about COW is premature
> optimization. For instance, when it comes to configuring a server at
> startup I really don't care too much about extra data copies.

Absolutely. On the other hand there's clearly a category of useful applications. I'll mull over a DIP.


Andrei
1 2 3 4 5 6 7 8 9
Next ›   Last »