473,729 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Survey: Frequency of usage of smart pointers

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 code or other people's code
you have come across would be appreciated. I am also trying to identify the
likelihood nad frequency of scenarios where smart pointer solutions would
not be appropriate, i.e. for some reason such as performance or complexity.
Oh, and if you feel like mentioning your favourite smart pointer libraries
that would be appreciated as well!

Thank you very much!

Christopher Diggins
http://www.cdiggins.com
Jul 22 '05 #1
9 2150
"christophe r diggins" <cd******@video tron.ca> wrote in message
news:aM******** ************@we ber.videotron.n et...
I would like to survey how widespread the usage of smart pointers in C++
code is today.
I've never used them (except for experimentation in the interest
of learning). But then again, I don't write huge amounts of C++
code either.
Any anecdotal experience about the frequency of usage of
smart pointer for dynamic allocation in your own code or other people's code you have come across would be appreciated.
So far, all my needs for dynamically allocated objects have been
served by the standard containers.
I am also trying to identify the
likelihood nad frequency of scenarios where smart pointer solutions would
not be appropriate, i.e. for some reason such as performance or complexity.

I really don't think such a statistic would be meaningful unless
it were broken down into contextual categories. Performance and
(high vs low) complexity will fall under different levels of priority
for various solutions. Almost always a high priority for me (in
any language), is clarity of expression (i.e. maintainability ).
IMO the standard containers meet this criterion quite well. IOW,
not only don't I use smart pointers, I rarely use 'new', 'delete'
or their array forms.
Oh, and if you feel like mentioning your favourite smart pointer libraries
that would be appreciated as well!


Sorry, don't have one.

-Mike
Jul 22 '05 #2

christopher diggins wrote:
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 code or other people's code
you have come across would be appreciated.
I have used some form of smart pointer since '2000 in 3 separate large
projects. They have all been the "intrusive" type (not boost::shared_p tr).

In the newer projects they are used very liberally. Virtually any
dynamically allocated object is managed with reference counted smart
pointers and no API's use any raw pointers for any classes that are
designed to be dynamically allocated.

YMMV.

I am also trying to identify the likelihood nad frequency of scenarios where smart pointer solutions would
not be appropriate, i.e. for some reason such as performance or complexity.
In multithreaded applications, reference counting needs to be done using
a significantly more expensive (up to 100 times more expensive depending
on HW) "atomic" increment/decrement, so I use a different "smart"
pointer when passing pointers in cases when I know that the object will
not be deleted during the life of the function call, hence eliminating 2
(or more) times the overhead of incrementing and decrementing the
reference count. Austria C++ smart pointers have "Ptr<>",
"PtrDelegat e<>" and "PtrView<>" smart pointer variants that (if used
correctly) can eliminate much of the wasted increment/decrement of
reference counts.
Oh, and if you feel like mentioning your favourite smart pointer libraries
that would be appreciated as well!


Austria C++. (as the author you can't expect me to write anything else!)
Jul 22 '05 #3

"christophe r diggins" <cd******@video tron.ca> wrote in message
news:aM******** ************@we ber.videotron.n et...
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 code or other people's
code you have come across would be appreciated. I am also trying to
identify the likelihood nad frequency of scenarios where smart pointer
solutions would not be appropriate, i.e. for some reason such as
performance or complexity. Oh, and if you feel like mentioning your
favourite smart pointer libraries that would be appreciated as well!


I would say that they get used in most new projects I work on. They aren't
very good at interfacing with legacy code that uses raw pointers however.
That would be my only reason not to use them.

Efficiency has never ever been a concern, and smart pointers reduce
complexity dramatically, so I can't see either of those objections being
applicable very often.

john
Jul 22 '05 #4

"christophe r diggins" <cd******@video tron.ca> skrev i en meddelelse
news:aM******** ************@we ber.videotron.n et...
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 code or other people's
code you have come across would be appreciated. I am also trying to
identify the likelihood nad frequency of scenarios where smart pointer
solutions would not be appropriate, i.e. for some reason such as
performance or complexity. Oh, and if you feel like mentioning your
favourite smart pointer libraries that would be appreciated as well!

Thank you very much!

Christopher Diggins
http://www.cdiggins.com


I've used smart pointers since i wrote my first serious C++-project in 1996.
Since then I haven't called delete outside that class (except for testcode,
perhaps).
I should start boosts smartpointer library, but i've come to like my own
class and laziness has prevented the refactoring.
/Peter
Jul 22 '05 #5
----- Original Message -----
From: "christophe r diggins" <cd******@video tron.ca>
Newsgroups: comp.lang.c++
Sent: Thursday, November 11, 2004 7:48 PM
Subject: Survey: Frequency of usage of smart pointers

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 code or other people's code you have come across would be appreciated. I am also trying to identify the

They are the norm in all of my projects. The only place I seem to ever write
a
'new' is in the argument list to the smart pointer constructor. I can't
remember
the last time I typed d-e-l-e-t-e. The older applications that I've
inherited
were in C++ written by C programmers. Most of the bugs I found were
corrected by
replacing manual dynamic allocation with smart pointers and/or std
containers
likelihood nad frequency of scenarios where smart pointer solutions would
not be appropriate, i.e. for some reason such as performance or complexity.

Certainly the more complex the application there's even more reason to use
smart
pointers versus manual memory management. The Glow Code profiler has never
pointed to shared_ptr as a performance bottleneck.

Aah, I do remember writing delete now. It is called in a class derived from
MFC's CTreeCtrl. It manages the lifetimes of it's node data, which holds a
unsigned long casted polymorphic pointer. I've never been comfortable with
this
arrangement and eventually plan to re-design an entirely new tree view
class, or
to have the existing class have a std::set< shared_ptr<Tree Itm> > and store
a
key in the node data struct.
Oh, and if you feel like mentioning your favourite smart pointer libraries
that would be appreciated as well!


1) boost::shared_p tr
2) boost::scoped_p tr
2) std::auto_ptr

Jeff F
Jul 22 '05 #6

"christophe r diggins" <cd******@video tron.ca> wrote in message
news:aM******** ************@we ber.videotron.n et...
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 code or other people's
code you have come across would be appreciated. I am also trying to
identify the likelihood nad frequency of scenarios where smart pointer
solutions would not be appropriate, i.e. for some reason such as
performance or complexity. Oh, and if you feel like mentioning your
favourite smart pointer libraries that would be appreciated as well!


1) Fully fledged thread safe smart pointers are must in cross architecture
systems, eg Java/C++
2) Shared pointers are useful in heavy mathematical applications with
optimized low level memory access. Main advantages are math algorithms code
simplification and facilitation of various fine-grained implementation
extension (as opposed to interface extension) policies that is when you
provide a placeholder for a hanlde that must be fill elsewhere:

template<typena me T>
struct Handle
{
smartPtr<T> ptr;
};

template<typena me t1, typename t2>
class User
: protected Handle<t1>, protected Handle<t2>
{

};

Combination of both requirements is standard eg for any modern banking
(trading/risk management) system.

std::auto_ptr is useless in most cases; boost stuff is most useful.

d
Jul 22 '05 #7
"christophe r diggins" <cd******@video tron.ca> wrote in message news:<aM******* *************@w eber.videotron. net>...
I would like to survey how widespread the usage of smart pointers in C++
code is today.
Well, member variables, local variables, function parameters,
function return values.

Any anecdotal experience about the frequency of usage of smart pointer for dynamic allocation in your own code or other people's code
you have come across would be appreciated.
If you want to hook C programmer to start with C++ show him/her smart
pointers and exceptions.:)

I am also trying to identify the likelihood nad frequency of scenarios where smart pointer solutions would
not be appropriate, i.e. for some reason such as performance or complexity.
Smart pointers are just subroutines, that code must be written
with or without them. Try without and see what I mean :)
Oh, and if you feel like mentioning your favourite smart pointer libraries
that would be appreciated as well!


std::auto_ptr

Greetings, Bane.
Jul 22 '05 #8
On Thu, 11 Nov 2004 19:48:59 -0500, "christophe r diggins"
<cd******@video tron.ca> wrote:
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 code or other people's code
you have come across would be appreciated.
How about "almost all the time"?

I couldn't begin to count the lines of code I had to refactor which
was written by a colleague who allocated character arrays with new[]
and invariably used plain delete instead of delete[] on the pointer,
simply forgot to delete at all, or his code was not exception safe
(meaning that delete was skipped if an exception was thrown). Believe
it or not, there are many programmers working in the real world who
have never heard of smart pointers.

Of course, I used std::string as often as possible, but there were
times when a non-const buffer was required. Now I would probably use
std::vector<cha r>, but this was before the standard required memory
allocation of vector to be contiguous (or before I knew about it<g>).

So I used either an array allocated on the stack if the size was known
in advance; if not, we used a modified form of the "grin pointer"
written by Allan Griffiths (see:
http://www.octopull.demon.co.uk/arglib/). Essentially, I just added a
bool argument indicating whether plain delete or array delete should
be used, and since we only needed automatic deletion and didn't need
to copy them, I stripped out that part of the code.

The grin pointer was also used for implementing classes with the
"pimpl idiom" in cases where pointers to more than one implementation
class were kept as members and these needed to be allocated in the
constructor's initialization list. Grin works well on incomplete types
which are merely forward declared in the header and only included
later in the .cpp file.
I am also trying to identify the
likelihood nad frequency of scenarios where smart pointer solutions would
not be appropriate, i.e. for some reason such as performance or complexity.
Some smart pointers are inappropriate for use in containers, e.g.
std::auto_ptr<> .
Oh, and if you feel like mentioning your favourite smart pointer libraries
that would be appreciated as well!


I think the Boost library pretty much covers it all. But check out
Allan Griffith's site as well.

--
Bob Hairgrove
No**********@Ho me.com
Jul 22 '05 #9
Thank you everyone, the contributions on the smart pointers have been
consistently excellent, and extremely insightful!

Christopher Diggins
http://www.cdiggins.com
Jul 22 '05 #10

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

Similar topics

27
3403
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined as ff: typedef struct { float *data ; int count ;
11
2197
by: Rajeev | last post by:
Dear friends I am conducting a survey on Relational Database usage and would like your help. The study is part of my MBA Dissertation. Could you kindly spare 5 minutes to take part in this survey? http://FreeOnlineSurveys.com/rendersurvey.asp?id=120816 Thanks
8
5149
by: Axter | last post by:
I normally use a program call Doxygen to document my source code.(http://www.stack.nl/~dimitri/doxygen) This method works great for small and medium size projects, and you can get good documentation like the following: http://axter.com/smartptr Now I'm on a client site, and I'm trying to create the same type of documentation on a very large project. I ran the Doxygen program, and it ran for over 16 hours, before I had
92
5107
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, but I just don't know. I don't like them because I don't trust them. I use new and delete on pure pointers instead. Do you use smart pointers?
33
5066
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 actual counting. Here is the latter's definition: // --- Begin ReferenceCountable.h ---------- class ReferenceCountable
54
11991
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 the advantages of smart pointers endlessly (which are currently used in all our C++ software; we use the Boost smart pointers) as I'm seriously concerned that there is a shift to raw pointers. We are not developing system software but rather...
4
3379
by: Alia Khouri | last post by:
Can we open up the discussion here about how to improve setuptools which has become the de facto standard for distributing / installing python software. I've been playing around with ruby's gems which seems to be more more mature and usable. From my perspective, the relative immaturity of setuptools and its simultaneous widespread use is a clear python weakness and can make python less easy to absorb than it should be. A few...
0
8923
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...
1
9203
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
9151
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
6722
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
6025
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
4529
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
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
2
2686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.