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: Paul Johnson
Subject: Re: [Swarm-Support] Objects on multiple lists
Date: Mon, 17 Feb 2003 18:29:50 -0600
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003

Darold Higa wrote:
Dear All:

This is probably a really dead and beaten horse, but I couldn't find specific references to it...so here it goes. I was going about trying to improve my code and in the process I decided to use collections more agressively , but now I have some unusual problems.

Here are my questions:

1. When an object creates an internal collection, it seems that I can only do so by creating it within the ModelSwarm zone. Is there no way to create temporary or instance collections internal to that object? My only fear is by creating them within the ModelSwarm zone, I might leave collections lying about when the objects that create them are destroyed by my reaperqueue. I thought I understood zones, but now I fear that maybe I don't, so any help here is appreciated.

I tried to do:

localAgentList = [List create: self];

but had to do

localAgentList = [List create: [modelSwarm getZone]];

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 case I had an object create a temporary list and assigned it the value of another list from another object. (I guess I should have used copy.) In any case, when I sent a removeAll command to the temporary list, the objects were removed from the original list as well. How does this work? I planned to have objects be on many lists at once, and I am not sure how manipulating collections affect other collections.

If you create a separate zone for each agent, and create the agent in that zone, then each agent will have a zone. But it does not solve the memory leak problem. When you drop the agent, you have to override the drop method and then make sure you drop the list when the agent is dropped.


To make it clearer, I have a master list of agents (for scheduling purposes), then at each geographic cell in my world there is a list tracking what agents are in that cell, then I also wanted each agent to maintain their own internal lists of agents with similar identities, who they interacted with, etc.

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]];

? Or does it have to do with objets on multiple lists that I do not understand.

I don't see what the problem is. If each agent has a list of others, and you remove all of those references, then everything gets removed. That's what happens on my computer, anyway.

If that's not what you see, give us a set of code we can test.



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?

I don't think it has been answered or discussed much. I think the answer is that the "other lists" will go to hell if you drop an object and you don't tell those other lists about it.

It would be a perfect world if those other lists had "nil" inserted where the dropped object used to be, but I was just reminded that it is not so. I had some hairy memory problems in a program that users sent me and the problem was that they were dropping an object from one list, but not setting it to nil or removing from the other lists, and so when processing those other lists, there was a seg fault because any old thing was found at the memory location where the dropped object was.

Lesson: keep careful track when dropping things, make sure they notify all lists in which they belong that they are gone.

pj


--
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700



reply via email to

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