|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-22 09:38:13
From: "Gabriel Dos Reis" <gdr_at_[hidden]>
> "Peter Dimov" <pdimov_at_[hidden]> writes:
>
> | > A fairly painless step in that direction would be to use
> | > std::allocator instead of std::operator new to allocate
> | > handles.
> |
> | I think that it might prove somewhat painful, as shared_ptr allocates
> | objects of different types (counted_base_impl<P, D>) and a
std::allocator<T>
> | can only allocate T.
>
> I can't follow. typename std::allocator<T>::template rebind<U>::other
> can allocate U.
Yes. I don't know how a typical std::allocator would behave, but standard
containers typically allocate objects of a single type; they rebind once, if
at all. Would std::allocator<void>::template
rebind<U>::other().allocate/deallocate (for varying U's) be an optimization?
Difficult to say.
What I see as the "right way" (if there is one) to optimize shared_ptr
allocations is
class counted_base
{
// ...
#ifdef BOOST_ENABLE_COUNTED_BASE_NEW
void * operator new(std::size_t);
void operator delete(void *, std::size_t);
#endif
};
The rest (Wheel Reinvention 101: Writing a Better Allocator) is outside
shared_ptr's scope as a library, IMO. If someone invests the (substantial, I
think) time and effort to make a competitive Boost.Allocator, it would be
silly to limit its use to shared_ptr counts.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk