Hello Carsten,

"Carsten Neumann" <carsten_neum...@gmx.net> schrieb im 
Newsbeitrag news:4f4fa2b3.3030...@gmx.net...
> On 03/01/2012 05:16 AM, Johannes Brunen wrote:
>> I have another problem/misunderstanding with respect to deep cloning.
>>
>> I have a ChunkMaterial which I need to clone. The material has embedded
>> ClipPlaneChunks with properly initialized beacon fields. Now, I have
>> discovered that the ClipPaneChunks of the deep copied ChunkMaterial
>> still has initialized beacon fields, but on calling getBeacon() on them,
>> I got a Null pointer. Inspection revealed that the _iRefCount is zero
>> which prevents returning the beacon object in the following code:
>
> 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:
The weak_ptr class template stores a "weak reference" to an object that's 
already managed by a shared_ptr. To access the object, a weak_ptr can be 
converted to a shared_ptr using the shared_ptr constructor or the member 
function lock. When the last shared_ptr to the object goes away and the 
object is deleted, the attempt to obtain a shared_ptr from the weak_ptr 
instances that refer to the deleted object will fail: the constructor will 
throw an exception of type boost::bad_weak_ptr, and weak_ptr::lock will 
return an empty shared_ptr.

So, this is another kind of weak pointer, with different semantics, I guess?

>
> 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.

Best,
Johannes





------------------------------------------------------------------------------
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

Reply via email to