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

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



On Fri, Jun 25, 2004 at 02:57:42PM -0400, Bob Ippolito wrote:
> 
> On Jun 25, 2004, at 2:51 PM, Pat Johnson wrote:
> 
> >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?
> 
> You could try storing png files in memory instead, should get you 
> better compression than zip without the 
> python-manipulating-fake-file-objects kind of overhead that doesn't 
> really make sense for what you want anyway.
> 
> -bob
> 

Or just convert the image to a string, and compress that with zlib...