Boost logo

Boost :

From: Fisher; Damien Kaine (dfisher_at_[hidden])
Date: 2001-08-20 05:27:25


Hi,

I have been following the discussion on shared_ptr and possible
extensions/improvements. While I can (partly) appreciate the reluctance
to add additional template parameters to shared_ptr, I must say that I do
not use shared_ptr in my code as commonly as I would like (well, need :) )
to incorporate an MT-safe increment/decrement reference count. (Eg,
InterlockedIncrement/InterlockedDecrement on Win32 system).

Would there be any chance of at least providing an additional Count
parameter whereby the user could possibly overload the reference counting
mechanism? This could also, if designed suitably, take care of situations
where the reference count is an intrinsic part of the object pointed to
(COM objects come to mind).

Of course, providing such a parameter would require very careful
documentation of the semantics of the class, particularly to handle
MT-safe applications. I would suggest something similar to the COM
reference count:

class Count
{
    // increment
    void increase();

    // decrement. true <==> the count hits 0
    bool decrease();
};

I believe that this should cover all possible situations.

Someone (sorry, can't remember who) commented that adding a template
parameter halves the possible user base. I would disagree in this case -
I think it is very important to provide a way to customize the reference
count, and 99% of users would use the default (which, with inlining, would
make diddly-squat difference). I would suggest that a good analogy
for this case would be std::allocator.

Damien


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