On Saturday 01 December 2001 01:50 pm, Jeff 'japhy' Pinyan wrote: > $x = "_" x 100_000; > $a = $x; $b = $x; $c = $x; > > $x is now copy-on-write, with three dependents. > > $x = "foo"; > > According to you model, we've just copied 300,000 bytes. Personally, I > find that unacceptable. Ben Tilly said it best on PerlMonks: if a > language is going to use copy-on-write, it should use it extensively. > > In COW, when a variable has more than one dependent, then when it gets > written to, we... > > 1. copy our contents to our first dependent > 2. move the rest of our dependents to that first dep's list of dependents > 3. update their master (to the first dependent) > > I believe that holds water. > > $x = 'foo'; > > We copy the 100,000 byte string to $a, $a gets $b and $c as dependents, > and $b and $c accept $a as their master. Far less work. You like?
Treat the string as an opaque structure. $x = "_" x 100_000; # $x points to a buffer "_" x 100_000 $a = $x; $b = $x; $c = $x; # $a, $b, and $c now point to that buffer. Any mods will # now need to be copied. > > $x is now copy-on-write, with three dependents. No. The buffer "_" x 100_000 is now COW with 4 dependents. > > $x = "foo"; $x gets a new buffer. In this case, since you're doing an assigment, you don't even need to copy the old buffer. For your original concern, the regex engine shouldn't be COW-aware; it should simply work on whatever buffer is given to it. -- Bryan C. Warnock [EMAIL PROTECTED]