Converting a bidimensional list in a bidimensional array
Diez B. Roggisch
deets at nospam.web.de
Fri Jan 11 19:36:19 CET 2008
Santiago Romero schrieb:
>>> - 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?
With these requirements, there is no need to jump through hoops to try
and save memeroy. You even can load levels from disk while the player
moves through the world.
Seriously - even a decade old machine would have had enough ram for
this. And nowadays .5GB to 2GB are the minimum. Don't waste time you
could spend designing a nice game on saving memory....
More information about the Python-list