monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] cvsimport branch reconstruction


From: Nathaniel Smith
Subject: Re: [Monotone-devel] cvsimport branch reconstruction
Date: Tue, 12 Sep 2006 18:28:34 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

On Tue, Sep 12, 2006 at 11:26:31PM +0200, Markus Schiltknecht wrote:
> Hi,
> 
> Uff, I'm having a hard time getting used to C++. I thought I may 
> probably just ask here. When exactly do I use shared_ptr?
>
> I want to have a map for
> (author_id, changelog_id) -> vector<resync_information>
> 
> resync_information holds three timestamps and yet another vector of 
> cvs_events.
> 
> Comming from C, I'm thinking in terms of pointers, so I'm currently 
> trying this:
> 
> map<metadata, vector< shared_ptr<resync_information> > > resync_revs;
> 
> Under what circumstances can I leave away the shared_ptr? Is that the 
> right way to build such a map?

It's pretty rare to actually need to use a shared_ptr in C++.  You
could certainly use a type like
  map<metadata, vector<resync_information> >

Hard to say without more details; the usual reasons to need a
shared_ptr is that you have some object whose lifetime is funny and
complicated and only determined at runtime (e.g., you can't say "this
goes away when this stack frame exits", or "this goes away when this
other object goes away").  This is pretty rare.  The other reason is
speed -- sometimes you need to pass an object around to various
places, but profiling tells you that copying is too expensive.

It's probably possible to get away without one in your case; I dunno
for sure, though.

-- Nathaniel

-- 
"Lull'd in the countless chambers of the brain,
Our thoughts are link'd by many a hidden chain:
Awake but one, and lo! what myriads rise!
Each stamps its image as the other flies"
  -- Ann Ward Radcliffe, The Mysteries of Udolpho




reply via email to

[Prev in Thread] Current Thread [Next in Thread]