Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Implementation of shared_ptr
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="James Kanze, post: 3783276"] In general, if you're allocating objects dynamically, it's because they have identity, and aren't copiable. (There are doubtlessly exceptions, but they aren't that common.) So just ban copy and assignment. The client code can always reactivate it for his classes, if it makes sense. That's one reason to use intrusive reference counting, but it's not the only one, nor even the most important one. Non-intrusive reference counting is extremely brittle; with boost::shared_ptr, for example, you need to take extrodinary precautions to ensure that you don't end up with two distinct counters. (The Boost documentation suggests making all of the pointers to the object boost::shared_ptr. Which is fine, but the compilers I use don't collaborate---this isn't a boost::shared_ptr.) That's for the cases where reference counting is appropriate, of course. which aren't all that frequent to begin with. The interlocked access is necessary regardless of the strategy. On the other hand, I find that when an object is being passed between threads, auto_ptr is more appropriate: once the second thread has access, you don't want to allow access from the first thread. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Implementation of shared_ptr
Top