 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Allerdyce.John@gmail.com Guest
|
Posted: Mon Jan 23, 2006 5:12 am Post subject: Smart Pointer library in C++ |
|
|
I think Smart Pointer library in C++ is implemented using reference
count.
How does smart pointer library detect if there is a circular
reference? and if yes, what does it do about it?
Thank you.
|
|
| Back to top |
|
 |
Luke Meyers Guest
|
Posted: Mon Jan 23, 2006 5:37 am Post subject: Re: Smart Pointer library in C++ |
|
|
[email]Allerdyce.John (AT) gmail (DOT) com[/email] wrote:
| Quote: | I think Smart Pointer library in C++ is implemented using reference
count.
How does smart pointer library detect if there is a circular
reference? and if yes, what does it do about it?
|
What library are you referring to? There is no standard smart pointer
library for C++. The only thing that's even close is std::auto_ptr,
which does not use refcounts because it transfers ownership on copy.
Maybe you're referring to boost::shared_ptr? If so, that's off-topic
here, but to briefly answer your question: it doesn't detect cycles,
it's up to the programmer to keep that from happening. Cycle detection
would be a property of a full-scale GC system, more overhead than I'm
willing to accept from a comparatively lightweight smart pointer type.
If you're curious about the implementation details, just go read
boost/shared_ptr.hpp.
Luke
|
|
| Back to top |
|
 |
Kai-Uwe Bux Guest
|
Posted: Mon Jan 23, 2006 6:25 am Post subject: Re: Smart Pointer library in C++ |
|
|
Luke Meyers wrote:
| Quote: | Allerdyce.John (AT) gmail (DOT) com wrote:
I think Smart Pointer library in C++ is implemented using reference
count.
How does smart pointer library detect if there is a circular
reference? and if yes, what does it do about it?
What library are you referring to? There is no standard smart pointer
library for C++. The only thing that's even close is std::auto_ptr,
which does not use refcounts because it transfers ownership on copy.
|
Well, there is tr1::shared_ptr, formerly known as boost::shared_ptr.
| Quote: | Maybe you're referring to boost::shared_ptr? If so, that's off-topic
here
[snip] |
I beg to differ: Boost libraries are the most canonical candidates for
standardization. Thus, they are directly relevant to "planned extensions
and adjustments" as mentioned in the FAQ:
Only post to comp.lang.c++ if your question is about the C++ language
itself. For example, C++ code design, syntax, style, rules, bugs, etc.
Ultimately this means your question must be answerable by looking into the
C++ language definition as determined by the ISO/ANSI C++ Standard
document, and by *planned extensions and adjustments*. (Emphasis added)
The fact that boost::shared_ptr now is in tr1 illustrates this point.
Also, Boost libraries, which strive to be as platform independent as
possible, have been by and large regarded topical on this news group for
quite some time.
Best
Kai-Uwe Bux
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|