Design notes updated.

[SVN r14575]
This commit is contained in:
Peter Dimov
2002-07-23 19:12:40 +00:00
parent 018c401e47
commit 77ad156c52

View File

@ -196,7 +196,29 @@ void bad()
<P><EM>[This constructor has been changed to a template in order to remember the actual <P><EM>[This constructor has been changed to a template in order to remember the actual
pointer type passed. The destructor will call <STRONG>delete</STRONG> with the pointer type passed. The destructor will call <STRONG>delete</STRONG> with the
same pointer, complete with its original type, even when <STRONG>T</STRONG> does same pointer, complete with its original type, even when <STRONG>T</STRONG> does
not have a virtual destructor, or is <STRONG>void</STRONG>.]</EM></P> not have a virtual destructor, or is <STRONG>void</STRONG>.</EM></P>
<P><EM>In the current implementation, if <STRONG>p</STRONG> is convertible to <STRONG>counted_base
*</STRONG>, <STRONG>shared_ptr</STRONG> will use the embedded reference
count supplied by <STRONG>counted_base</STRONG>. This is an (experimental)
attempt to provide a way for <STRONG>shared_ptr</STRONG> to be constructed from
a raw pointer such as <STRONG>this</STRONG>. A free function <STRONG>shared_from_this(q)</STRONG>
performs the conversion when <STRONG>q</STRONG> is convertible to <STRONG>counted_base
const *</STRONG>.</EM></P>
<P><EM>The optional intrusive counting employed by the current implementation allows <STRONG>
shared_ptr</STRONG> to interoperate with <STRONG>intrusive_ptr</STRONG>, an
experimental generic intrusive-counted smart pointer.</EM></P>
<P><EM> Another possible implementation is to use a global pointer-to-count map instead
of intrusive counting. <STRONG>shared_from_this</STRONG> would no longer be
O(1), which is a concern for some users, although I do not expect any
performance problems, since the operation is rare. Maintaining a global
map&nbsp;is difficult; it needs to be initialized before any <STRONG>shared_ptr</STRONG>
instances are constructed, and the initialization needs to be&nbsp;thread safe.
In addition, under the Windows dynamic library model, it is possible for
several maps to exist.</EM></P>
<P><EM> It is not yet clear which implementation should be used, or whether the
specification should allow both; nevertheless,&nbsp;the ability to make a <STRONG>shared_ptr</STRONG>
from <STRONG>this</STRONG> is considered essential&nbsp;by experienced smart
pointer users.</EM><EM>]</EM></P>
<pre>template&lt;typename Y, typename D&gt; shared_ptr(Y * p, D d);</pre> <pre>template&lt;typename Y, typename D&gt; shared_ptr(Y * p, D d);</pre>
<blockquote> <blockquote>
<p><b>Requirements:</b> <B>p</B> must be convertible to <B>T *</B>. The copy <p><b>Requirements:</b> <B>p</B> must be convertible to <B>T *</B>. The copy
@ -605,7 +627,8 @@ int * p = a.release();
implementation or a linked list implementation, or some other specific implementation or a linked list implementation, or some other specific
implementation. This is not the intent.</p> implementation. This is not the intent.</p>
<hr> <hr>
<p>Revised <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->23 July 2002<!--webbot bot="Timestamp" i-checksum="38439" endspan --></p> <p>Revised <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->
23 July 2002<!--webbot bot="Timestamp" i-checksum="38439" endspan --></p>
<p>Copyright 1999 Greg Colvin and Beman Dawes. Copyright 2002 Darin Adler. <p>Copyright 1999 Greg Colvin and Beman Dawes. Copyright 2002 Darin Adler.
Copyright 2002 Peter Dimov. Permission to copy, use, modify, sell and Copyright 2002 Peter Dimov. Permission to copy, use, modify, sell and
distribute this document is granted provided this copyright notice appears in distribute this document is granted provided this copyright notice appears in