473,387 Members | 1,812 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,387 software developers and data experts.

shared_ptr design question

g
Hello,

Wouldn't be better shared_ptr constructor to have an argument
<true/falsefor thread-safe reference counting?? The default should be
true and in case you dont want thread-safe RC create a shared_ptr with
false in constructor. The reason for this is to avoid the cost of the
memmory barriers where you don't need them.

At the moment if your application is multithreaded boost will choose to
use thread-safe RC but in many cases( local containers with
shared_ptrs) thread-safe RC doesn't have any sense.....becouse the
objects are owned by only one thread.

in this cases, the best way to go is to use an instrusive_ptr where the
developer implements the RC??

thanks in advance,

Jan 6 '07 #1
2 1627
g wrote:
>
Wouldn't be better shared_ptr constructor to have an argument
<true/falsefor thread-safe reference counting?? The default should be
true and in case you dont want thread-safe RC create a shared_ptr with
false in constructor. The reason for this is to avoid the cost of the
memmory barriers where you don't need them.

At the moment if your application is multithreaded boost will choose to
use thread-safe RC but in many cases( local containers with
shared_ptrs) thread-safe RC doesn't have any sense.....becouse the
objects are owned by only one thread.
I think you're right that you shouldn't have to pay for sychronization
when you don't need it, I think a better approach is to have two
different types of shared pointer instead of one that may or may not be
synchronized. On the other hand, cases where you truly need to share
heap-allocated objects between threads are probably sufficiently rare
that maybe there's no need for synchronization at all. James Kanze, on
comp.std.c++, has suggested that auto_ptr is sufficient for sharing
objects between threads: create it in one thread and pass it to another.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Jan 6 '07 #2
"g" <ge*******@yahoo.comwrote:
Wouldn't be better shared_ptr constructor to have an argument
<true/falsefor thread-safe reference counting?? The default should
be true and in case you dont want thread-safe RC create a shared_ptr
with false in constructor. The reason for this is to avoid the cost
of the memmory barriers where you don't need them.
I agree in general, but I don't think a constructor argument would be
the best choice. Better would be a templated proxy ala the shared
pointer class in Loki.
Jan 6 '07 #3

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

Similar topics

2
by: Derek | last post by:
Something puzzles me about Boost's shared_ptr implementation: template <typename T> class shared_ptr { public: T* operator->() const { return p; }
4
by: Ernst Murnleitner | last post by:
Hello, in 2 other threads I had questions partly related to shared_ptr. I changed my normal pointers to a class to shared_ptr. (i.e. boost::shared_ptr). I thought, the use of shared_ptr is...
8
by: ralpe | last post by:
Hi, I have a question regarding boost::shared_ptr. I want to let shared_ptr take care of my objects' lifetimes, so I change all my function signatures so that they accept shared_ptrs instead of...
6
by: Sean | last post by:
I have a boost::shared_ptr and want to detach the primitive pointer within it so I can keep using it even after the shared_ptr is destroyed. Is there a way to do this?
14
by: PengYu.UT | last post by:
In the following program, I want an iterator contain pointer pointing to constant object not const pointer. If it is possible would you please let me know how to do it? #include...
3
by: Emmanuel Deloget | last post by:
Hello y'all, I'm currently writing a serie of blog tickets about the TR1, both from a definition point of view and from an implementation point of view. The next iteration in the series deals...
14
by: Tim H | last post by:
I understand the semantics of why this works the way it does. But I wonder if there's a reason for the behaviore at the line marked "QUESTION". I figured if there is an answer, someone here knows...
5
by: Fokko Beekhof | last post by:
Hello all, please consider the following code: -------------------------------------------------- #include <tr1/memory> struct BaseA { int x;
5
by: .rhavin grobert | last post by:
are there any pro's and con's in using references to shared_ptr<>'s ? example: __________________________________________________ void obj::foo(shared_ptr<>); vs. void...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.