在这种情况下如何有效地使用 intrusive_ptr ?
我已经阅读了很多有关 smart ptr 的内容,并决定将 intrusive_ptr 与我自己的实现一起用于引用计数。
这么说,我现在必须面对另一个问题,考虑到weak_ptr不能与auto_ptr类一起使用,如何解决引用循环。
使用应该存储弱引用的原始指针来解决循环是一件好事吗?这样做的后果是,如果强引用被删除,弱引用将不会被通知/归零,但我认为正确构建依赖关系可能是一个不错的选择,但我在这里可能是错的。
有人可以对此发表任何意见吗?
I have read a bunch about smart ptr, and have decided to use intrusive_ptr with my own implementation for reference counting.
Said that, I have to face now another problem, how to solve reference cycles taking into account weak_ptr can't be used with the auto_ptr class.
Will it be a good thing to resolve the cycles using raw pointers where weak references should be stored? The consecuences of this are that if the strong reference is deleted weak references will not be notified/zeroed, but I think that arquitecting correctly the dependencies it could be a good option, but I could be wrong here.
Could anybody give any opinion about this?.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用
shared_ptr
。它更容易使用,并且可以与您提到的weak_ptr
一起使用。也许有一天您会发现需要使用侵入式的情况,但在那之前,请保持简单。Just use
shared_ptr
. It's easier to use, and works withweak_ptr
which you mentioned. Maybe someday you'll find a case where you want to use intrusive, but until then, keep it simple.