|
Boost Users : |
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-09-28 04:59:32
Cory Nelson wrote:
> It would be useful if shared_ptr and family provided a way to give a
> custom allocator. For instance, to replace the quick allocator with a
> lock-free one.
boost::shared_ptr is already ready to accept allocators:
http://www.boost.org/libs/smart_ptr/shared_ptr.htm
template<class Y, class D> shared_ptr(Y * p, D d);
template<class Y, class D, class A> shared_ptr(Y * p, D d, A a);
Requirements: p must be convertible to T *. D must be
CopyConstructible. The copy constructor and destructor of D must not
throw. The expression d(p) must be well-formed, must not invoke
undefined behavior, and must not throw exceptions. A must be an
Allocator, as described in section 20.1.5 (Allocator requirements) of
the C++ Standard.
Effects: Constructs a shared_ptr that owns the pointer p and the
deleter d. The second constructor allocates memory using a copy of a.
Postconditions: use_count() == 1 && get() == p.
Throws: std::bad_alloc, or an implementation-defined exception when
a resource other than memory could not be obtained.
Exception safety: If an exception is thrown, d(p) is called.
Notes: When the the time comes to delete the object pointed to by
p, the stored copy of d is invoked with the stored copy of p as an argument.
Regards,
Ion
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net