I'm creating a game that has a lot of high definition images, at 30 FPS, so performance is kind of a big issue to this particular situation. I was checking the memory consumption and realized that a set of images, that has 2~3mb in the hard drive, when loaded to game, it occupye's 30mb. Is there a way to decrease memory consumption without compromising too much the CPU usage?
-
230Mb does not seem like much. Are you certain that's the source of your performance issues? – jonrsharpe Oct 28 '14 at 19:31
-
Decrease the size of the images, perhaps. – Anthony Oct 28 '14 at 19:32
-
jonrsharpe 30mb is not much, but thats only 1 set of images. The game has about 27 sets, therefore, in the worst cenario, 810mb would be occuping RAM – Pedro Forli Oct 28 '14 at 19:39
1 Answers
You're talking about a set of image files. These image files are, however, most likely compressed, hence the smaller file size. To find the uncompressed size of all of your images, you should compute the memory footprint of each of them (most likely width * height * bytes per pixel
(3 bytes for RGB, 4 for RGBA). How does that compare to your 30 MB memory footprint (For example, a RGB image that is 1680x1080 screen, you will need ~5.3 MB of memory for the screen)?
To answer your question: I don't think you will be able to reduce the memory footprint of your application (without sacrificing CPU) easily. Graphics cards (GPU) are able to work with compressed textures/images (e.g. DXT), and it seems PyGame might be too (search for 'compressed' in the PyGame Surface documentation), but I can't find anything in PyGame that would let you choose whether or not you want compressed textures or where the textures actually reside (video memory, operating memory, both). It probably depends on the OS and HW you're running under.
One way might be to reduce the resolution of the files or only load the files you need for that specific scene.
Someone with a better knowledge of PyGame might provide further insight.

- 532
- 1
- 5
- 16
-
Thank You, i just tested what you said and it was pretty accured. Loading a png set and a tga set ends up in the same memory allocation, so i guess i will look for some more specific advice now – Pedro Forli Oct 28 '14 at 20:37