swarm-support
[Top][All Lists]
Advanced

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

Re: [Swarm-Support] Objects on multiple lists


From: Steve Railsback
Subject: Re: [Swarm-Support] Objects on multiple lists
Date: Mon, 17 Feb 2003 16:13:28 -0800

Darold Higa wrote:
> 

I can answer some but not all your questions...maybe somebody else will
answer about zones.

> Here are my questions:
> 
...

> 2.  Is there some way to determine what effect having the same object in
> multiple collections will have?  I don't remember where I read/heard it, but
> I thought it was OK for an object to exist in multiple collections, since
> collections were pointers to the specific instances of an object.  In one

That's right.

 
> To make a long and complicated question hopefully shorter, is the problem
> that I had with removeAll a result of my use of :
> 
> temporaryAgentList = [terrainObject getLocalAgentList];
> 
> instead of
> 
> temporaryAgentList = [[terrainObject getLocalAgentList] copy [modelSwarm
> getZone]];

To make a simple answer short, Yes. temporaryAgentList, the way you
programmed it, is just another name for the list inside your
terrainObject. Instead, you need to make a new list and put the same
objects on both (if that's what you want). 

So any object can be on as many lists as you want, each list is just a
list of pointers to that object. Just be careful when you go to drop an
object that you go through all the lists that it is on and remove it
from those lists. (Or you can maintain one master list of objects that
still exists, and continually empty and re-build your temporary lists-
may not be the fastest code but often it's the fastest way to get your
job done.)
 
> 2A.  If a list is made of objects through addLast, what effect will removing
> and or dropping items from this list have on any other lists?

*Removing* an object from a list does not affect the other lists. If you
*drop* an  object that is still on a list somewhere, you are asking for
trouble. If your code tries to do anything with all the objects on a
list and some of those objects have been dropped (e.g., by using
deleteAll on another collection containing the object) your code will
crash. Best to always remove an object from all the lists it is on, then
delete it.
 
> I have targetAgentList as a subset of localAgentList.  If I eventually remove
> all from the targetAgentList, will it affect localAgentList?

Don't think so...not sure what you mean by 'subset'. But again, removing
something from one list has no effect on another list.
 
Some of this is described in the reference manual - look in the section
on the Collections library and look at "Collection"- lists etc. are
subclasses of Collection. 

Steve

-- 
Lang Railsback & Assoc.
250 California Ave.
Arcata CA  USA 95521
707-822-0453; fax 822-1868


reply via email to

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