Converting a bidimensional list in a bidimensional array

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Jan 11 12:50:46 EST 2008


Santiago  Romero:
>  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.
>  Do you think I should still go with lists instead of an H-type array?

1 MB or RAM may be small enough nowdays, so you may use lists.
If not, then the array.array solution can be good.
You may even store just the rows of your images as arrays, so you can
use the usual syntax [][].
Another alternative is to use some external numerical lib, it's quite
useful if you use pygame, to blit, process images, store and process
bitmaps, etc.

Bye,
bearophile



More information about the Python-list mailing list