Markus Laire wrote:
> I've been following this list for a month, but havn't yet learned what COW
> really means. It's used so often that perhaps it should be added to Parrot
> Glossary.

I'll give my try, but I'm no expert at all. feel free to correct me if I'm
wrong.

COW stands for Copy On Write. it means that when you have to copy a string,
the "real" string to be copied (eg. its content, eg. the bytes) is not
really copied in memory with the copy operation.
rather, the new string is marked as COW, and it still points to the original
string. when you read that string, you are "redirected" to the original
one.

but when you want to write something to the string (eg. modify it), then
the system notes the COW flag and performs the actual copying of bytes
(possibly a part of them, if you are modifying only part of the string).

this approach saves memory, because you can create as many copies of a
string as you want, without allocating it many times. unless you modify
them, at least. it's also usually a great speed boost, because copying a
string is performed in O(1) time, instead of O(n) - where n is the size of
the string.

hope this helps :-)


cheers,
Aldo

__END__
$_=q,just perl,,s, , another ,,s,$, hacker,,print;

Reply via email to