473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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.

Jan 23 '06 #1
10 2366
Al************@gmail.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.

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

Jan 23 '06 #2
Luke Meyers wrote:
Al************@gmail.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.

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

Jan 23 '06 #3
"Kai-Uwe Bux" <jk********@gmx.net> wrote in message
news:dr**********@murdoch.acc.Virginia.EDU...
Luke Meyers wrote:
Al************@gmail.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.

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.


I basically agree. The interesting issue for the Off Topic Police is to
determine whether a Technical Report developed by WG21 and approved by
ISO as an extension to Standard C++ is still off topic because it's a
non-normative document. Gonna be hard to learn about all the goodies in
TR1 (which, as you say, are all candidates for inclusion in C++0X) if
we can't discuss them in more-or-less polite company.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jan 23 '06 #4
Al************@gmail.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?

Thank you.


If I'm not mistaken, the boost::week_ptr is suppose to be used to help
stop circular reference with the boost::shared_ptr

Jan 23 '06 #5
P.J. Plauger wrote:

I basically agree. The interesting issue for the Off Topic Police is
to determine whether a Technical Report developed by WG21 and
approved by ISO as an extension to Standard C++ is still off topic
because it's a non-normative document. Gonna be hard to learn about
all the goodies in TR1 (which, as you say, are all candidates for
inclusion in C++0X) if we can't discuss them in more-or-less polite
company.

"Candidates for" doesn't mean standard. I don't have much objection to
discussing what's in the TR and how the features might be used if the
TR is incorporated into the revised standard (although such discussion
might be better on comp.std.c++).

My objection with Boost has always been people just recommending it
without noting its non-standard nature. There are people working in C++
who can't just use any old third-party library they want. As nifty keen
as Boost is, until it's actually in a standard library that's its
status as well.

When the TR came out, I dropped my objections for the most part.
Brian

Jan 23 '06 #6
Default User wrote:
P.J. Plauger wrote:

I basically agree. The interesting issue for the Off Topic Police is
to determine whether a Technical Report developed by WG21 and
approved by ISO as an extension to Standard C++ is still off topic
because it's a non-normative document. Gonna be hard to learn about
all the goodies in TR1 (which, as you say, are all candidates for
inclusion in C++0X) if we can't discuss them in more-or-less polite
company.

"Candidates for" doesn't mean standard. I don't have much objection to
discussing what's in the TR and how the features might be used if the
TR is incorporated into the revised standard (although such discussion
might be better on comp.std.c++).

My objection with Boost has always been people just recommending it
without noting its non-standard nature. There are people working in C++
who can't just use any old third-party library they want. As nifty keen
as Boost is, until it's actually in a standard library that's its
status as well.

When the TR came out, I dropped my objections for the most part.


I object to not being able to talk about the boost library in general,
because currently the normal track for getting new candidates for the
standard, is to first have it added to the boost library, and after a
good review, and usage, then it's considered for TR and then for the
official standard.
If you cut off talking about boost, you're killing potential inputs to
the standard, and you're possibly killing potentially good review and
critiques for candidates to the language.

I also don't think you should have to put a disclaimer every time you
make a post referring to the boost library.
IMHO, this is common enough knowledge that the user should already know
he/she is being referred to non-STL code.

IMHO, if topic-police posters think the disclaimer needs to be added,
than let them added themselves.

Jan 23 '06 #7
Axter wrote:

I object to not being able to talk about the boost library in general,
because currently the normal track for getting new candidates for the
standard, is to first have it added to the boost library, and after a
good review, and usage, then it's considered for TR and then for the
official standard.
If you cut off talking about boost, you're killing potential inputs to
the standard, and you're possibly killing potentially good review and
critiques for candidates to the language.
Shouldn't those discussions take place on comp.std.c++?
I also don't think you should have to put a disclaimer every time you
make a post referring to the boost library.
Why not?
IMHO, this is common enough knowledge that the user should already
know he/she is being referred to non-STL code.
Most of the people who get references to Boost have little knowledge
about what is and is not standard.
IMHO, if topic-police posters think the disclaimer needs to be added,
than let them added themselves.


For the most part, the topic police tend to be staring up at that
clouds and whistling a happy tune with Boost roars down the street.
There are a few of us who object, but as I said I've more given up on
mere referrals.

Brian
Jan 23 '06 #8
Default User wrote:
Axter wrote:

I object to not being able to talk about the boost library in general,
because currently the normal track for getting new candidates for the
standard, is to first have it added to the boost library, and after a
good review, and usage, then it's considered for TR and then for the
official standard.
If you cut off talking about boost, you're killing potential inputs to
the standard, and you're possibly killing potentially good review and
critiques for candidates to the language.


Shouldn't those discussions take place on comp.std.c++?


Yes, but there's a limited feedback on the comp.std.c++, and a long lag
time between discussions since the group is moderated.
What may take a few hours here, takes a few days to discuss there.

Jan 23 '06 #9
Kai-Uwe Bux wrote:
Luke Meyers wrote:
Well, there is tr1::shared_ptr, formerly known as boost::shared_ptr.
Maybe you're referring to boost::shared_ptr? If so, that's off-topic
here
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:
snip<

The fact that boost::shared_ptr now is in tr1 illustrates this point.


Fair point. What I was really trying to point out was that the OP did
not make it clear what the hell smart pointer type was being referred
to.
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.


Marvelous. I like Boost, after all.

Luke

Jan 23 '06 #10
Axter wrote:
Default User wrote:

Shouldn't those discussions take place on comp.std.c++?


Yes, but there's a limited feedback on the comp.std.c++, and a long
lag time between discussions since the group is moderated.
What may take a few hours here, takes a few days to discuss there.


That's fine. It should be noted that I don't believe I've ever objected
to a discussion of what might be comin' down the pike. My own grumbles
were due to people suggesting Boost as solutions to problems presented
here without clarifying the nature of the solution.

Brian
Jan 23 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mohammad | last post by:
Is there a difference between smart pointers and automatic pointers or they refer to the same idea. -Thanks
6
by: Johnny Hansen | last post by:
Hello, I've been trying to implement smart pointers in C++ (combined with a reference counter) because I want to do some memory management. My code is based on the gamedev enginuity articles,...
9
by: christopher diggins | last post by:
I would like to survey how widespread the usage of smart pointers in C++ code is today. Any anecdotal experience about the frequency of usage of smart pointer for dynamic allocation in your own...
9
by: BekTek | last post by:
How do you think? and why?
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
14
by: Ian | last post by:
I am looking at porting code from a C++ application to C#. This requires implementing data sharing functionality similar to what is provided by a smart pointer in C++. I have only recently begun...
33
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.