|
Boost : |
From: Gregory Colvin (gregory.colvin_at_[hidden])
Date: 2003-08-28 18:33:19
On Thursday, Aug 28, 2003, at 16:26 America/Denver, E. Gladyshev wrote:
> --- Gregory Colvin <gregory.colvin_at_[hidden]> wrote:
>>> How will I even know it, the documentation is completely
>>> ignorant on the memory issues.
>>
>> Perhaps because you work with the authors of the documentation to
>> make it sure it says what needs saying?
>
> Are the documentation authors monitoring this mailing list?
>
>> And I have no objection myself to adding an allocator parameter
>> to the shared_ptr constructor, or to making some other change that
>> serves the purpose. So if you need a change, why not just do it,
>> try it out, and submit a patch?
>
> How about
>
> template< typename T, typename Counter = int >
> shared_ptr
> {
> typedef Counter counter; //counter type should be public
>
> template <typename DataAlloc = std::allocator<T>, typename
> CounterAlloc=std::allocator<counter>
>>
> shared_ptr( const DataAlloc& da = DataAlloc(), const IntAlloc ia& =
> CountAlloc() );
> };
shared_ptr doesn't allocate the data, it only deletes it, which is the
job of the
current deleter parameter. And the counter type is by design not part
of the
shared_ptr type, so it doesn't belong as parameter to the shared_ptr
template.
See:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/boost/boost/boost/
shared_ptr.hpp
So you what you might want is to add something more like this to
shared_ptr:
template<typename Data, typename Deleter, template<class Counter>
class Allocator>
shared_ptr(
Data*,
Deleter,
const Allocator<boost::detail::sp_counted_base_impl<Data*,
Deleter> >& );
The idea being that you can use this constructor to get complete
control over how
a particular shared_ptr manages memory.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk