View Single Post
Old 11-06-2003, 05:02 AM   #5
Kastagaar
Member
 
Join Date: Apr 2002
Location: Hampshire, UK
Posts: 117
Kastagaar is on a distinguished road
Send a message via Yahoo to Kastagaar
The most probable cause for infinite looping is, in my opinion, bad design. DikuMUDs in particular suffer from this because of their linked-list design. They use the idiom of "a data element in the list is a node in the list". Consider:

[code] a -> b -> c -> a[/quote]

We can see that iterating this is an infinite loop, because the node a points to the node b. Now consider using the "list node and data element are distinct" option:

[code]
node -> node -> node -> node
a b c a
[/quote]

(Eh? the code tag is not monospaced?)

Even though a is incorrectly in the list twice, there is no infinite loop when iterating over the list because the last node is still the last node.

This approach has its drawbacks, though: it takes more memory and probably more (although negligible) processor time when iterating. It also requires more memory management, because each node must be dynamically created.
Kastagaar is offline   Reply With Quote