Cyclic Objects

BlitzMax Forums/BlitzMax Programming/Cyclic Objects

gellyware(Posted 2005) [#1]
It seems that if an object creates an instance of object2 (which object2 creates a new list) then a cyclic pattern occurs. Why? How can this be fixed?

Here is an example and a screen shot of the debug that cycles infinitely....

Type TParent
	Field cycle:TCycle = New TCycle 
EndType 

Type TCycle
	Field list:TList = New TList 
EndType 

Global parent:TParent = New TParent
FlushMem
DebugStop 






Dreamora(Posted 2005) [#2]
This might be because field cycle:TCycle = XXXX isn't really defined when it has to be exectuted.

This is the correct way of doing it:

Type TParent
	Field cycle:TCycle
	
	Method New ()
		cycle = New TCycle 
	End Method
EndType 

Type TCycle
	Field list:TList  
	Method New ()
		list = New TList
	End Method
EndType 

Global parent:TParent = New TParent
FlushMem
DebugStop 


(Initialisation of data in constructor )


gellyware(Posted 2005) [#3]
I just ran your code and the same result happens using debugstop


Bot Builder(Posted 2005) [#4]
Hey lucid,

This is because internally the head/tail object (in bmax's lists, it's both) for some reason points to itself as a value rather than having a null.

http://www.blitzbasic.com/Community/posts.php?topic=49183

^My hierarchy module of awesomeness.

Even then, both TList and Hierarchy are cyclic. One node points to the next and that points to the previous. Its not infinite in memory or anything like that, only in a treeview like that. If it was something more interesting like a network view it would have only as many as actually exist.


gellyware(Posted 2005) [#5]
Hi Bot,

So basically what you are saying is that it is ok to see the head/value repeating like this in the debug?

Also I will check out your hiearchy module :))


gellyware(Posted 2005) [#6]
One quick question bot, what is the advantage of your module over the TList


Bot Builder(Posted 2005) [#7]
Main advantages are:

*Editing the list while iterating it
*Easy support of hierarchies of TLists
*String splitting
*Group extends node, so no need to create a node in order to create a child group.
*Overall more finding/editing commands
*Access to the current node while enumerating
*prolly more