[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using collections
From: |
Ken Cline |
Subject: |
Re: Using collections |
Date: |
Thu, 16 Jan 1997 23:30:33 -0500 (EST) |
Thanks, Glen.
Two more questions:
1. If you pass a collection to another class which in turn
creates another reference to the same collection. Then, in
the original class, the collection goes out of scope. The
second class now has a dangling reference, right?
For example:
Our agents are given a list of goals (coordinates) to
attain. As the agent approaches it current goal, the goal is
set to the next on the list. (BTW, goals are analogous to a
carrot on a stick, i.e. all other things being equal, the
agent will move towards its goal... but, I digress...)
The goal list is created in the model swarm's build
objects method and passed to the agent. The goal list is
local to the build objects method and should therefore be
"freed" when the build objects method returns.
However, after trying it both ways, it doesn't seem to
matter whether the receiving agent copyies the goal
list or simply makes a reference to the list. ...Hmmm?
...Perhaps this is blind luck?
2. I've discovered that a list index doesn't perform any
bounds checking in the "next" method. That is, if you call
[index next] when you are at the "End" of the list, then you
get a core dump.
However, [index getLoc] doesn't return "End" until after
you moved past the last list element. Therefore, when I'm
traversing the list, I test two conditionals:
([index getLoc] != End) and ([index next] != nil).
Have I overlooked an more direct way of stopping at the
end of a list? Is there a method to "peek" ahead without
moving the index? Perhaps the "getOffset" method can be
used to accomplish this?
Thanks again,
Ken.
_________________________________________________________
Ken Cline address@hidden
SAIC VOICE (410) 571-0413
Annapolis, MD FAX (301) 261-8427
- Using collections, Ken Cline, 1997/01/15
- Re: Using collections, glen e. p. ropella, 1997/01/17
- Re: Using collections, glen e. p. ropella, 1997/01/17
- Re: Using collections, glen e. p. ropella, 1997/01/23
- Re: Using collections, Roger M. Burkhart, 1997/01/23
- Re: Using collections, Roger M. Burkhart, 1997/01/27
- Re: Using collections, Kevin Crowston, 1997/01/27
- Re: Using collections, Roger M. Burkhart, 1997/01/28