Converting a bidimensional list in a bidimensional array
Santiago Romero
sromero at gmail.com
Fri Jan 11 08:06:21 EST 2008
> > - Speed Performance: Do you think that changing from list to Array()
> > would improve speed? I'm going to do lots of tilemap[y][x] checks (I
> > mean, player jumping around the screen, checking if it's falling over
> > a non-zero tile, and so).
> First of all: if you have enough memory to use a python list, then I
> suggest you to use a list.
>
> Often python lists are faster than array.array (maybe because python
> lists actually contain pyobjects).
My problem is that, in my game, each screen is 30x20, and I have
about 100 screens, so my tilemap contains 32*20*100 = 60000 python
objects (integers).
If each integer-python-object takes 16 bytes, this makes 60000 * 16 =
almost 1MB of memory just for the tilemaps...
Using array of type H (16 bits per item = 2 bytes), my maps take just
60000*2 = 120KB of memory.
After that, I just will access tilemap data for reading (i.e. value
= tilemap.GetTile(x,y)) ...
Do you think I should still go with lists instead of an H-type array?
More information about the Python-list
mailing list