Hi All,
is there a Copy-on-Write semantic behind PHP compiler?
$a = long_string_1mb;
$b = $a; // Compiler will allocates another 1MB for this variable.
I have to use "$b =& $a;" to avoid memory waste.
I think this should be done by compiler itself. For instance:
$a = lang_string_1mb; // Compiler will allocate a memory block and alter
variable $a point to this address. And set reference count of this
memory block to 1.
$b = $a; // Compiler will alter variable $b to the same memory block and
increment reference count to 2.
$b = some_string_else; // Compiler will allocate another memory block
for $b and decrement the previous reference count to 1.
This will be more efficient than managing referencing by ourselves.
--
Xu, Qian (stanleyxu)