[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] How to prevent sending a message to a droppedobject?
From: |
martijn cox |
Subject: |
Re: [Swarm-Support] How to prevent sending a message to a droppedobject? |
Date: |
Thu, 4 Aug 2005 20:09:02 +0200 |
Actually, I just copy/pasted that from the Sugarscape example you commented
on in accomponying the README (2003-04-18) :). I think I wasn't clear enough
in my previous post about the usage of the posetd code: It serves to clear a
reaperqueue of all its members, so I don't think the for-loop scheme is
necessary? You answered my question about how to access the pointer to the
agent I just deleted though, thanks!
----- Original Message -----
From: "Paul Johnson" <address@hidden>
To: "Swarm Support" <address@hidden>
Sent: Wednesday, August 03, 2005 9:01 PM
Subject: Re: [Swarm-Support] How to prevent sending a message to a
droppedobject?
> martijn cox wrote:
> > Well, that would indeed work, but the thing is: I don't have the pointer
to
> > the object available. All I can do is loop over a List of agents like
so:
> >
> > while( (agent = [index next]) != nil )
> > {
> > if ([agent getBirthAction])
> > [lifeMutationSchedule remove: [agent getBirthAction]];
> > [_agentList remove: agent];
> > [agent drop];
> > agent = nil; // ***
> > }
> >
>
> remove returns a pointer to the removed object. But I don't think you
> should remove items this way.
>
> FIrst, don't use the while construct, use for. If your while finds a
> nil in your list, the iterating will stop prematurely. Second, you are
> wrecking the index by removing a member while iterating. That's bad.
>
> I can give you a much better algorithm for doiing this that fixes all of
> these problems. Then it will be much cleaner & faster to remove with
> the index.
>
> id agent, index;
>
> index = [agentList begin: [self getZone]];
>
> for(agent = [index next]; [index getLoc]==Member; agent = [index next])
> {
>
> if ([agent getBirthAction])
> {
> id theAgent;
> [lifeMutationSchedule remove: [agent getBirthAction]];
> theAgent = [index remove];
> [theAgent drop];
> theAgent = nil;
> }
> }
>
> Actions on indexes to remove items are
> 1. safe to the index and
> 2. Much Much faster than searching through a collection to find
> something and remove it.
>
>
>
> --
> Paul E. Johnson email: address@hidden
> Dept. of Political Science http://lark.cc.ku.edu/~pauljohn
> 1541 Lilac Lane, Rm 504
> University of Kansas Office: (785) 864-9086
> Lawrence, Kansas 66044-3177 FAX: (785) 864-5700
>
>
- [Swarm-Support] How to prevent sending a message to a dropped object?, martijn cox, 2005/08/01
- Re: [Swarm-Support] How to prevent sending a message to a dropped object?, Paul Johnson, 2005/08/01
- Re: [Swarm-Support] How to prevent sending a message to a dropped object?, Ken Cline, 2005/08/01
- Re: [Swarm-Support] How to prevent sending a message to a droppedobject?, martijn cox, 2005/08/02
- Re: [Swarm-Support] How to prevent sending a message to a droppedobject?, Paul Johnson, 2005/08/02
- Re: [Swarm-Support] How to prevent sending a message to a dropped object?, martijn cox, 2005/08/03
- Re: [Swarm-Support] How to prevent sending a message to a dropped object?, Paul Johnson, 2005/08/03
- Re: [Swarm-Support] How to prevent sending a message to a droppedobject?,
martijn cox <=
- Re: [Swarm-Support] How to prevent sending a message to a dropped object?, Ken Cline, 2005/08/04
- Re: [Swarm-Support] How to prevent sending a message to a droppedobject?, martijn cox, 2005/08/09
- Re: [Swarm-Support] How to prevent sending a message to a droppedobject?, Paul Johnson, 2005/08/09