    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Copy on Write</title>
        <link>https://members.accu.org/index.php/journals/1240</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 15, #5 - Oct 2003 + Programming Topics</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c106/">155</a>
                    (10)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c106-65/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c106+65/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Copy on Write</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 October 2003 13:16:00 +01:00 or Fri, 03 October 2003 13:16:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e18" id="d0e18"></a></h2>
</div>
<p>What exactly is Copy On Write (COW)? This has been the source of
some discussion on <tt class="literal">accu-general</tt> just
recently. Copy on Write is a lazy optimisation [Jim Hyslop].
Consider a string-class implemented in such a way that it only
stores a pointer to a string of data [Terje Sletteb&oslash;].</p>
<div><img src="/var/uploads/journals/resources/string_class.gif"></div>
<p>The normal way to make a copy of such an object would be to
create a new instance of the object, allocate enough memory to hold
the string and then copy the string from the old object into the
newly allocated memory pointed to by the new object. This is called
a Deep Copy. However, if the string data is particularly long it
may be quicker to just copy the value of the pointer from one
instance of the string-object to the other and have both instances
pointing at the same string data.</p>
<div><img src="/var/uploads/journals/resources/mulit_string_class.gif"></div>
<p>Then you have to make sure that if one of the string-objects
modifies the string data the other does not get its string data
modified as well [Terje Sletteb&oslash;]. So we need a way of
determining whether more than one string points to the same data
[Phil Nash]. This is achieved by introducing a system of reference
counting. Every time a new copy of the string-object is created the
reference count in incremented. The reference count is decremented
again each time one of the string-objects is destroyed. When the
reference count falls to 0 the string itself is destroyed.</p>
<p>But how does this stop an instance of the string-object
modifying the string data pointed to by all the other
string-objects? Each time a string-object wants to modify the
string data it checks the reference count. If the reference count
is 1 it knows it is the only string-object pointing at the string
data and it can modify it however it wants. If the reference count
is greater than 1 it must perform a deep copy (as described above)
and decrement the reference count by 1. This process of not
performing a deep copy until the 'data' needs to be modified is
termed Copy On Write.</p>
<p>However, for many programs though the average string is
approximately six characters long. The extra overhead of COW,
including the difficulty of identifying when a write operation is
about to take place [Phil Nash], takes more time than just doing
the deep copy. Once multi-threading is taken into account it
becomes very difficult to make COW work correctly for an object
such as std::string and the extra overhead of needing to
synchronize (even for distinct strings used in different threads,
if they might be copies of the same string) is an extra nail in the
coffin [James Dennett].</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
