Boost logo

Boost :

From: Fisher; Damien Kaine (dfisher_at_[hidden])
Date: 2001-09-03 12:51:17


What would be wrong with something like:

template<class T, class RC = some_default_refcounter>
class shared_ptr
{
...
};

where the RC template parameter conforms to:
class RC
{
    void add(T *p);
    bool release(T *p);
};

normal extrusive refcount:
class boring_rc
{
    boring_rc() : count(1) {}
    void add(T *) { ++count; }
    bool release(T *p) { return --count == 0; }
};

overloaded intrusive refcount (say for a COM object):
class com_rc
{
    void add(T *p) { p->AddRef(); }
    bool release(T *p) { return p->Release() == 0; }
};

ok, so it is *ugly* - I admit! But it is fast - nothing tricky, any old
compiler should be able to handle it. No performance trade-offs that I
can see.

I haven't done much reading about this "policy-based" stuff, but from
reading examples people have posted previously they seem to essentially
boil down to additional template parameters. Is this a correct
assumption? Any recommended online reading on this (I am but a poor uni
student who cannot afford his instant noodles let alone books, so URIs
would be preferred :) )?

I also can't think of any sane ref counting algorithm which could not
operate within the above interface. Then again, you people in the
northern hemisphere have always done things backwards anyway :).

Damien

On Mon, 3 Sep 2001, Peter Dimov wrote:

> From: "David Abrahams" <david.abrahams_at_[hidden]>
> > From: "Peter Dimov" <pdimov_at_[hidden]>
> > > Although my point was more along the lines that even given a
> policy-based
> > > smart pointer, your particular case would most probably still call for
> an
> > > old school, hand written implementation.
> >
> > I don't see why. Why do you say that?
>
> It seems to me that you needed a type that
>
> * is like shared_ptr, but with an intrusive count, i.e. has reference
> semantics;
> * is a dynamically-allocated array, i.e. has a constructor like
> my_shared_array(int n);
> * remembers this 'n', i.e. has a size() member.
>
> This is something that is halfway between shared_array and vector. In a
> situation like this I'd have created a shared_ptr<vector<T> >-based
> prototype first. I assume that you didn't like the performance of the
> prototype.
>
> Perhaps I've misunderstood, but I think that a policy-based design would
> likely allow you to specify interface and behavior, but not provide the
> tools necessary to achieve the low-level customizations needed for this kind
> of performance-tuning. I may be wrong.
>
> --
> Peter Dimov
> Multi Media Ltd.
>
>
> Info: http://www.boost.org Unsubscribe: <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk