Hi Johannes, On Fri, Mar 2, 2012 at 2:20 AM, Johannes Brunen <jbru...@datasolid.de> wrote: >> the beacons are only held with weak pointers so that you can use an >> ancestor node as beacon without generating loops of ref counted objects >> - which then would not destroy properly. > > yes... > >> A weak pointer will prevent the destructor of the pointed-to object from >> running, but only so that the weak pointer has a chance to actually >> notice that it's pointed-to object is actually dead. That is what the >> code below handles: > > My understanding of a weak pointer is different. It should not prevent > destruction of the pointed-to object, but give means to test, if it is still > available. Isn't that the way the boost shared_ptr weak_ptr are designed, > for instance? > > >From the boost documentation: ... > > So, this is another kind of weak pointer, with different semantics, I guess?
Hm, not really. Internally the boost:weak_ptr does the same thing we do (initially i wanted to use the boost pointers, but there were a few things boost wouldn't give us access to, so we did our own). The semantics are the same: you can get a real ptr from the weak ptr, as long as there is at least one other real ptr to the referenced object, otherwise you get NULL (or an exception in the boost case). >> >> well, it wasn't explicitly designed to behave in this somewhat >> unexpected way, but I don't think there is much the generic deepClone() >> can do to handle this better - for starters it would have to return a >> sequence of parent-less nodes (the root of the tree you clone and >> parent-less beacons in the tree). >> > That means, that deep cloning is quite a dangerous operation! Generally, you > don't know about the details (beacons) of the tree you are cloning... > > Howerver, I have understood, that my design is flawed at this point, and I > will look for a proper solution. I wouldn't say your design is flawed, it's just that deepClone is not taking weak ptrs into account completely correctly. Carsten, Gerrit: what about the following semantics: deepClone could keep track of the FCs it is cloning (probably does that already anyway), and if it finds a reference (or weak reference) to an FC that is being cloned, repalce it with the clone. If it finds a reference to outside the cloned tree just keep it. Johannes, I'm assuming you're deleting the original tree at some point, after which the beacons disappear and the problems start. With the changed behavior as long as your deepClone contains the beacons things would work. It it doesn't contain the beacons there is not a whole lot we can do, besides Carsten's suggestion of fairly major semantic changes to deepClone. Would that fix your problem? Yours Dirk ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ _______________________________________________ Opensg-users mailing list Opensg-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensg-users