|
Boost Users : |
From: Jim.Hyslop (jim.hyslop_at_[hidden])
Date: 2003-07-17 09:36:23
Jason Winnebeck wrote:
> I am converting my old network library that uses explicit memory
> management to use shared_ptr where appropriate. So far this has gone
> well but I am having problem with cycles.
[...]
> One could use a weak pointer in the Generator to the
> Listener, but then
> the Listener may die as soon as it is registered.
That's OK, though - each time the Generator wants to use the Listener, it
constructs a shared_ptr out of the weak_ptr it has. If the shared_ptr is
NULL, the Generator knows the Listener has gone away, and can take the
appropriate steps to unregister the Listener.
> ... the Listener is defined by the user. So I prefer to
> make the task as easy as possible on the user -- so I want to
> allow the
> user to use weak or strong references if possible so he
> doesn't have to
> worry about cycles.
If you want to make things easy for the user, don't offer them a choice.
Choice means complexity. Complexity is bad. Require the user to use a
shared_ptr to the Generator.
-- Jim
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