On 8-Apr-07, at 11:56 AM, Karen wrote:
>
> On Apr 8, 2007, at 11:22 AM, Frank Condello wrote:
>
>> ou can make a self-cleaning tree in RB code without weakrefs, though
>> you need to call the plugin API's Lock/Unlock functions - the
>> framework provides these if you know where to look ;) I use this
>> technique to travel a 3D scenegraph upwards from a leaf node and have
>> been very satisfied with the results.
>
> What do you mean?

The RB plugin API has methods to "Lock" and "Unlock" objects - i.e.  
raise and lower their reference counts. You can use strategic locks/ 
unlocks to trick circular refs into cleaning up after themselves in  
certain situations, but you can also crash horribly so I won't  
encourage anyone to do this. A tree structure is relatively safe and  
I can whip up an example if there's enough interest, but for RB2007r2 
+ users the WeakRef class is your best bet.

> BTW there is a way to do tree Structures without all of that... But
> it's messy and takes a lot of code to make work dynamically.
>
> Put the tree members in an array or dictionary and use array indexes
> or dictionary keys in the nodes as pointers to parent and child.
> While you still effectively have them, that eliminates circular
> references for reference counting memory management purposes

Yes that's reasonable as well. I use a dictionary in a similar  
fashion to keep track of textures and vertex buffers that have been  
uploaded to the GPU. Using an array for this sort of thing would be  
more of a pain than it's worth however, since indexes can and will  
change when things are removed/inserted. I really needed to avoid the  
dictionary overhead for my node class however, since the tree is  
traversed entirely from the root several times per frame, and  
individual nodes might iterate backwards through their parents  
several more times per frame.

Frank.
<http://developer.chaoticbox.com/>
<http://macgameblog.com/>


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to