[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Subtle Memory Bug



James Hofmann wrote:
I'd agree. I've been in similar situations before.
What's really wanted(once the problem is discovered)
are these two properties:

1. references to list locations, rather than specific
items
2. can "step backwards" when size/ordering changes

I tend to use a while loop and counter for those purposes.

So, like this?

foo = [<instance>, <instance>, etc.]
n = 0
while n < len(foo):
    foo[n].DoStuff() ## Might result in deleting foo[n]
    n += 1

I think I've done something like that before, but I don't remember whether len(foo) gets evaluated anew each time. I may have had to say:

n = 0
done = False
while not done:
    DoStuff()
    if n >= len(foo):
        done = True

This issue is relevant to my AI code, if I ever really sit down and work on it. I'd been using a big dictionary of neuron-like objects and cycling through them each turn, giving each of them "links" containing ID numbers used to access other units. Instead I might eliminate the ID numbers altogether and give the units direct references to each other, eg.:

scint.LinkTo( otherscint )
as opposed to:
scint.LinkTo( otherscint.ID )

Kris