Content deleted Content added
Rescuing 1 sources and tagging 0 as dead.) #IABot (v2.0.9.3) (Whoop whoop pull up - 12943 |
reworded explanation. +comma. checked URLs. |
||
Line 2:
{{More citations needed|date=August 2020}}
'''Copy-on-write''' ('''COW'''), sometimes referred to as '''implicit sharing'''<ref>{{cite web |title=
When a resource will be duplicated (but not modified), it is not necessary to copy the contents of that resource because, with a little care, every copy can share the same stored contents. (The original counts as one copy because it does not matter which one was the original.) When and if a computer program begins to write into any copy (to change or modify it), the computer must first make a non-shared copy by actually copying the contents, and then write into the new copy. Hence the name of the technique. The actual copy operation is deferred until something needs to write into any copy (which might not ever happen before the copy is discarded). Sharing storage in this way can substantially reduce the consumption of resources by unmodified copies, at the cost of adding some overhead (testing and possibly additional storage) to resource-modifying operations.
==In virtual memory management==
Copy-on-write finds its main use in [[operating system]]s, sharing the [[
Copy-on-write can be implemented efficiently using the [[page table]] by marking certain pages of [[
The copy-on-write technique can be extended to support efficient [[memory allocation]] by
Copy-on-write pages are also used in the [[Linux kernel]]'s [[
==In software==
{{
COW is also used in [[
===Examples===
The [[
<syntaxhighlight lang="cpp">
std::string x("Hello");
Line 28 ⟶ 30:
</syntaxhighlight>
In the [[PHP]] programming language, all types except references are implemented as copy-on-write. For example, strings and arrays are passed by reference, but when modified, they are duplicated if they have non-zero reference counts. This allows them to act as value types without the performance problems of copying on assignment or making them immutable.<ref>{{cite web |last1=Pauli |first1=Julien |last2=Ferrara |first2=Anthony |last3=Popov |first3=Nikita |title=Memory management |website=PhpInternalsBook.com |date=2013 |url=
In the [[Qt (software)|Qt]] framework, many types are copy-on-write ("implicitly shared" in Qt's terms). Qt uses atomic [[compare-and-swap]] operations to increment or decrement the internal reference counter. Since the copies are cheap, Qt types can often be safely used by [[
==In computer storage==
COW may also be used as the underlying mechanism for [[
==See also==
|