swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Birth/Death


From: cgl
Subject: Re: Birth/Death
Date: Tue, 12 Nov 1996 10:54:29 -0700

Glen's caution is well taken - It is likely that the
model swarm is in the act of iterating over the
preyList via a ForEach command when one of the prey
attempts to add a new member to the preyList. This
could cause problems as the preyList is changing 
under its iterator. I'll defer to Roger as to whether
this is "safe" or not at the moment. Since you are
asking the preyList itself to add to itself, it should
be safe. However, in case this is not safe, another
option would be to create a preyToAdd list in the
modelSwarm, and pass in the pointer to that 
to each prey instance. Then, after the modelSwarm
finishes iterating over the preyList, you add code
to add the new prey on the preyToAdd list to the
preyList. Alternatively, it may be safe to add the
new prey to the preyList directly, if you always add
them to the beginning of the list, which presumably
the iterator has already passed over - again I
defer to Roger Burkhart who wrote the collections 
package on what the proper thing to do is, and
on the safety of modifying the preyList directly
underneath an active iterator.

On scoping in OO languages - one of the main features of
OOPs style is that objects themselves control access
to their internals, by providing methods and selectively
passing out direct access pointers to internal structures
(encapsulation). So, if you want one object to be able
to access a structure inside another object, either the
latter object has to provide a method that handles the
request, or it has to specifically hand a pointer to
the structure to the first object, which can then
reference it directly. The various "set" and "get"
methods are examples of the former, the setHeatSpace
method for a heatBug is an example of the latter, when
the modelSwarm passes a direct pointer to the heatSpace
object internal to the modelSwarm, which is then 
used by the heatBugs to talk to the heatSpace directly, 
without intervention of the modelSwarm.  

Cheers!

Chris Langton



reply via email to

[Prev in Thread] Current Thread [Next in Thread]