gcpp icon indicating copy to clipboard operation
gcpp copied to clipboard

Support for non-owning deferred_ptr

Open ratchetfreak opened this issue 9 years ago • 5 comments

Will there be support for non-owning deferred_ptrs that will not prevent objects being destroyed (don't participate in the mark phase) but will get nulled when the object they refer to gets destroyed? Like the semantics of a weak pointer in garbage collection.

ratchetfreak avatar Sep 28 '16 10:09 ratchetfreak

Yes, I intend to add that eventually because it's natural to want a weak version of a strong (shared) pointer type.

I'll probably put it off for a while as it's lower on the priority list, but I'll keep this issue open as a reminder.

hsutter avatar Sep 29 '16 20:09 hsutter

How about returning a shared_ptr with a customized dtor?

lichray avatar Oct 07 '16 05:10 lichray

How about returning a shared_ptr with a customized dtor?

@Zhihao: shared_ptr is an owning strong pointer, not a non-owning weak pointer, so users would expect it to keep the object alive. Also, the layout is incompatible – flavors of either shared_ptr or weak_ptr wouldn’t work because copying either one tries to access a reference count control block which doesn’t exist. The reason a different pointer type than shared_ptr was needed is because shared_ptr doesn’t have the copying and destruction properties needed, and the deleter doesn’t support sufficient customization to try to shoehorn it in.

hsutter avatar Oct 07 '16 10:10 hsutter

I see. I kind of want to save some types so that people can gain some homogeneity in containers etc. Well.

lichray avatar Oct 07 '16 10:10 lichray

Thanks again for this suggestion. For now I'm waiting for feedback and bug reports from actual use of the library, and deferring enhancements and optimizations until then but keeping them in the backlog.

hsutter avatar Nov 27 '16 20:11 hsutter