Large Array Handling

Erik Max Francis max at alcyone.com
Fri Dec 13 06:54:31 EST 2002


Richard Pasco wrote:

> I am fairly new to python and was wondering about its possibilities. I
> want
> to make a boxing management game, and on starting the game i need to
> populate the list of boxers. I was wondering how python will handle a
> large
> array of length 1000 * 20. In a fight situation, I will need the
> array's
> data for two fighters so rather than make the whole list global I
> should
> make a new array just holding the two fighters stats and pass that
> correct?
> Or will python be ok handling this size of information?
> Of course when I mean can it handle I mean both can it physically
> handle it
> and will the access speed be low enough to prevent long pauses in game
> play?

Python lists are implemented as vectors, so access to an element of a
list is an O(1) operation.  As long as the thing will physically fit in
memory, the size won't matter.

Certainly a list of a few tens of thousands of elements is no big deal
on a modern machine.

One of the best features about Python is that it's interpreted, so you
can just fiddle around with large arrays yourself:

>>> l = range(20000) # this is an array of length 20 000
>>> len(l)
20000
>>> l.reverse()
>>> import operator
>>> reduce(operator.add, l)
199990000

As you type these in, watch the response times of these commands.  Put
them in loops and repeat them many times and test how long it takes if
you want to get quantitative information.  On a modern machine, you
shouldn't be able to detect any noticeable delay; almost certainly it'll
be fast enough for your purposes.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Together we can take this one day at a time
\__/ Sweetbox
    Polly Wanna Cracka? / http://www.pollywannacracka.com/
 The Internet resource for interracial relationships.



More information about the Python-list mailing list