473,790 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

boost::shared_p tr vs. auto_ptr

Are there any advantages of using boost::shared_p tr other than auto_ptr from
standard library?

Jul 22 '05 #1
5 2922
* ctick:
Are there any advantages of using boost::shared_p tr other than auto_ptr from
standard library?


There are a number of advantages.

First, they're two different beasts: std::auto_ptr transfers ownership
so that with some caution you can guarantee that only one pointer points
to a particular object at any time, whereas boost::shared_p tr provides
reference counting so that many pointers can point to the same object.

Second, you cannot put std::auto_ptr's in a standard container, but you
can with boost::shared_p tr.

Third, although the standard specially provides for calling a destructor
on an object of incomplete class, not all compilers support that. This
problem pops up in e.g. the pimpl idiom. With boost::shared_p tr you
replace the direct delete expression in std::auto_ptr with a custom
destroy-function that can be defined where the full definition of the
class is available, side-stepping the issue.

I could list up a fourth and fifth advantage, and perhaps more, but I
think that's enough. The main advantage of std::auto_ptr is that it's
always there and that it's standard. It should therefore be used when
the generality of e.g. boost::shared_p tr is not required.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
On Sat, 19 Jun 2004 20:23:26 GMT in comp.lang.c++, al***@start.no (Alf
P. Steinbach) wrote,
I could list up a fourth and fifth advantage, and perhaps more, but I
think that's enough. The main advantage of std::auto_ptr is that it's
always there and that it's standard. It should therefore be used when
the generality of e.g. boost::shared_p tr is not required.


I think that auto_ptr also has less overhead cost than shared_ptr's
ownership tracking mechanism when you are doing the simple things it is
capable of and have no need for shared ownership.

Jul 22 '05 #3
"ctick" <ct***@flare.co m> wrote in message
news:g61Bc.6352 $OB3.4344@bgtns c05-
Are there any advantages of using boost::shared_p tr other than auto_ptr from standard library?


You're comparing apples to oranges.
Jul 22 '05 #4
Siemel Naran wrote:

"ctick" <ct***@flare.co m> wrote in message
news:g61Bc.6352 $OB3.4344@bgtns c05-
Are there any advantages of using boost::shared_p tr other than auto_ptr

from
standard library?


You're comparing apples to oranges.


http://www.people.virginia.edu/~rjh9u/apporang.html
Jul 22 '05 #5
In message <40************ ****@news.west. earthlink.net>, David Harmon
<so****@netcom. com.invalid> writes
On Sat, 19 Jun 2004 20:23:26 GMT in comp.lang.c++, al***@start.no (Alf
P. Steinbach) wrote,
I could list up a fourth and fifth advantage, and perhaps more, but I
think that's enough. The main advantage of std::auto_ptr is that it's
always there and that it's standard. It should therefore be used when
the generality of e.g. boost::shared_p tr is not required.


I think that auto_ptr also has less overhead cost than shared_ptr's
ownership tracking mechanism when you are doing the simple things it is
capable of and have no need for shared ownership.

For the _really_ simple things, consider boost::scoped_p tr. No
overheads, no sharing or transfer of ownership at all.

--
Richard Herring
Jul 22 '05 #6

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

Similar topics

4
3153
by: Philippe Guglielmetti | last post by:
I just ported old (VC6) working code to VC7.1 and have trouble with something like: class A; // forward typedef boost::smart_ptr<A> Aptr; class B{ Aptr a; virtual ~B(); // implemented after A has been defined };
6
9059
by: Ryan Mitchley | last post by:
Hi all Given bool bResult; shared_ptr<cSampleData> pNewData; shared_ptr<cBase> pNewBase; where cSampleData is descended from cBase, the following gives me a valid pNewData to the correct type:
2
4838
by: krema2ren | last post by:
Hi I've the following header problem that I need two classes to know each other through a boost::shared_ptr. Does any of you smart guys have a solution? A.h ---------------------- #include "B.h"
2
2138
by: adebaene | last post by:
Hello group, There seems to be a bug int the interop layer in VC2005 when dealing with certain pointer types (or values?) Here is a repro case using Boost version 1.32 and C++/CLI : using namespace System; #pragma unmanaged
6
4036
by: Toby Bradshaw | last post by:
Hi, Consider the following: class A { public: virtual bool foo() = 0; };
2
3082
by: ketan | last post by:
Hi, While reading the Boost::shared_ptr implementation, I came across this method template<class Tclass shared_ptr { ..... template<class Y> shared_ptr(shared_ptr<Yconst & r, boost::detail::const_cast_tag):
1
1982
by: rssmps | last post by:
Hi, first post and here it goes... This is the current code (working) that I have. It works but for large number of A & B objects, it's not the most efficient. It's also not really heterogenous either. It's really just a storage of the parent class objects. class A { … } class B:public A { … } vector<A*> combined;
4
3964
by: EnsGabe | last post by:
Suppose you have a class heirarchy as such: class Base{ .... }; class Mid1 : public Base{ ....
10
11623
by: tradevol | last post by:
Hi, I am playing with boost pointer and try to wrap the following codes A* func(){ ... if(condition 1 ){ return a; } else
0
9666
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
10200
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
10145
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
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7530
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
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
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...
1
4094
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
2909
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.