http://d.puremagic.com/issues/show_bug.cgi?id=2093





------- Comment #7 from [EMAIL PROTECTED]  2008-11-22 08:43 -------
(In reply to comment #4)
> Currently an 'owner' is anyone who has a pointer to array's beginning:
> 
> char[] s = "hello".dup;
> char[] s1 = s[0..4];
> s1 ~= "!";
> assert(s != s1); // fails, both are "hell!", s is overwritten

A simple char[] is fully mutable, so that doesn't violate any established rule,
but whether it's desirable is another matter.

With const(char)[] or invariant(char)[], obviously this isn't going to work, so
~= should always reallocate (unless the optimiser can be sure that no other
reference to the data can possibly exist).

Alternatively, the GC could maintain a note of the actual length of every
heap-allocated array.  Ownership would be determined by matching in both start
pointer and length.  When the length is increased, whether by .length or ~=,
either update this actual length (if it's the owner that we're extending, IWC
all other references to the same data lose ownership) or reallocate the array.


-- 

Reply via email to