develooper Front page | perl.perl6.internals | Postings from July 2002

Re: Parrot Glossary - COW

Thread Previous | Thread Next
Aldo Calpini
July 5, 2002 05:54
Re: Parrot Glossary - COW
Message ID:
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

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

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 :-)


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

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About