Converting a bidimensional list in a bidimensional array

Fredrik Lundh fredrik at pythonware.com
Fri Jan 11 13:34:35 EST 2008


Santiago Romero wrote:

>  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...

or more likely, 240k for pointers to a few distinct integer objects,
each of which occupies 16 bytes.

if you're really running this on a machine with only a few megabytes 
free memory, maybe you could compress the screens you're not working 
with?  zlib.compress(cPickle.dumps(screen)) should compress each 
640-item list to say, 50 to 500 bytes, depending on the contents.

</F>




More information about the Python-list mailing list