473,786 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.....becou se 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 1638
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.....becou se 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*******@yaho o.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
1692
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
1962
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 more save. But after this my program crashed by several reasons (see below). But maybe there would be an easy solution which I cannot see now.
8
2167
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 raw pointers. I wonder how to deal with cases where a this pointer is passed as an argument. Is it ok to write something like the following?
6
3574
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
2043
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 <boost/shared_ptr.hpp> #include <vector> #include <iterator> #include <iostream> class trial {
3
3227
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 with the smart pointer sub- library in the TR1 (weak_ptr, shared_ptr, enable_shared_from_this), and guess what, I have a few question about the implementation of all this. Before I ask my question, I'd like to say that I studied all the
14
6655
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 it. Specifically, part 1 is obvious to most anyone. Part 2 is isomorphic to part 1, yet behaves differently. If a shared_ptr is const, should it really allow non-const dereferences? Thanks,
5
3202
by: Fokko Beekhof | last post by:
Hello all, please consider the following code: -------------------------------------------------- #include <tr1/memory> struct BaseA { int x;
5
7663
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 obj::foo(shared_ptr<>&); and shared_ptr<>& obj::foo2(); vs. shared_ptr<obj::foo2();
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.