diff options
Diffstat (limited to 'content/xdocs/SharedPtr.html')
-rwxr-xr-x | content/xdocs/SharedPtr.html | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/content/xdocs/SharedPtr.html b/content/xdocs/SharedPtr.html new file mode 100755 index 0000000000..31effc4389 --- /dev/null +++ b/content/xdocs/SharedPtr.html @@ -0,0 +1,71 @@ +<html> + <head> + <title>Apache Qpid : SharedPtr</title> + <link rel="stylesheet" href="styles/site.css" type="text/css" /> + <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> + </head> + + <body> + <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff"> + <tr> + <td valign="top" class="pagebody"> + <div class="pageheader"> + <span class="pagetitle"> + Apache Qpid : SharedPtr + </span> + </div> + <div class="pagesubheading"> + This page last changed on Oct 19, 2006 by <font color="#0050B2">mmccorma</font>. + </div> + + <p>std::tr1::shared_ptr is an almost-standard smart pointer template that<br/> +provides unintrusive reference-counting semantics for any class. It<br/> +almost makes memory management too easy for a C++ programmer.</p> + +<p>It's available in g++ and some other compilers by default. There are<br/> +several open source implementations if we ever port to a compiler that<br/> +doesn't have it.</p> + +<p>The golde rule: if class Foo has shared ownership then never <em>ever</em><br/> +write <tt>Foo*</tt>. Anywhere. Ever. Use shared_ptr in all function<br/> +signatures and variables, use std::tr1::dynamic_pointer_cast and<br/> +friends for casting.</p> + +<p>Qpid will use it for all classes with shared ownership semantics,<br/> +enforced by private constructors and static factory functions. We'll<br/> +also adopt the convention to typedef shared_ptr within the class for<br/> +convenience. E.g.</p> + +<div class="code"><div class="codeContent"> +<pre class="code-java">class Foo {
+ Foo() { ... }
+
+ <span class="code-keyword">public</span>:
+ typedef std::tr1::shared_ptr<Foo> shared_ptr;
+ <span class="code-keyword">static</span> shared_ptr create() { <span class="code-keyword">return</span> <span class="code-keyword">new</span> Foo() }
+ <span class="code-comment">// .. a create <span class="code-keyword">for</span> each constructor.
+</span>}
+
+Foo::shared_ptr p = Foo::create(); <span class="code-comment">// etc...</span></pre> +</div></div> + + +<p>There's a good article at <a href="http://www.boost.org/libs/smart_ptr/sp_techniques.html" title="Visit page outside Confluence">http://www.boost.org/libs/smart_ptr/sp_techniques.html</a>.</p> + + + + + + </td> + </tr> + </table> + <table border="0" cellpadding="0" cellspacing="0" width="100%"> + <tr> + <td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td> + </tr> + <tr> + <td align="center"><font color="grey">Document generated by Confluence on Apr 22, 2008 02:47</font></td> + </tr> + </table> + </body> +</html>
\ No newline at end of file |