[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Using zipfile to reduce in-memory usage?



Hi all,

I've been working on the level manager for my game (used to re-organize, copy, delete, etc. game levels, and launch the level editor) and I'm wondering about memory usage and how to reduce it since I'm targeting lower end computer users. The level manager has eight level preview images to let the user what the each level looks like. The user can then navigate back and forth through 'pages' of these level previews.

Each preview takes awhile to generate depending on computer speed (1-2 seconds on a fast system) so I've got a separate thread that creates the preview image in the background and then stores the preview in a dictionary. This means that if a game world has 100 levels then there will be 100 associated preview images in memory. Each preview image is 151x98 at 32 bit color = ~60K per preview. Take that * 100 = ~6 MB for 100 preview images.

I'm wondering about use the zipfile module to compress the images _in memory_ (using a cstringio file-like object for the zip 'file'). The app would be able to append new or changed preview images, and read existing ones, from the zip file. Only the preview images visible on screen would be cached uncompressed. This also gives the benefit of being able to save the file of compressed preview images to disk in-between edit sessions--something I had planned to do anyway.

Another alternative is to use the zip file on disk but I don't have any idea if the speed would be acceptable on a slower machine.

I plan to try out some test code but I was wondering if anyone has comments or other suggestions on whether this is feasible?

-Pat
www.gamesinmind.com