Can this support boost::intrusive_ptr like usage?
Closed this issue · 4 comments
Wuqiqi123 commented
Get pointer from a intrusive_ptr to another intrusive_ptr like below, the reference count is not right
boost::intrusive_ptr<ProcessData> ptr(new ProcessData(1, "a"));
{
// get from another intrusive_ptr
boost::intrusive_ptr<ProcessData> ptrCopy(ptr.get());
}
explicit constexpr intrusive_ptr(_T * __t) noexcept
: __x_t(__t)
{
if (__x_t->_Impl_intrusive_ptr::_Ref_count_base::__get_ref() > 1)
__x_t->_Impl_intrusive_ptr::_Ref_count_base::__add_ref();
}
I __add_ref when old __x_t is not 1. Is this right?
lhmouse commented
Is your sample even valid if it was about std::shared_ptr
?
Wuqiqi123 commented
Inner pointer can not shared between std::shared_ptr, but boost::intrusive_ptr can
std::shared_ptr<T> ptr(new T());
std::shared_ptr<T> ptr2(ptr.get()); // It is not correct
boost::intrusive_ptr<T> ptr(new T());
boost::intrusive_ptr<T> ptr2(ptr.get()); // It is ok
But I find your intrusive_ptr can not do the same as boost::intrusive_ptr.
lhmouse commented
If you need to share (instead of taking) ownership of an object you have to call add_ref()
explicitly.
This repo does not accept Pull Requests.
Wuqiqi123 commented
If you need to share (instead of taking) ownership of an object you have to call
add_ref()
explicitly.This repo does not accept Pull Requests.
Thank you for your advice.