ETC memory best practices


Loaded some of my own PNG images to ITC over the weekend and my intention was to see how far I could go with fiel sizes and resolution. I was successful in getting memory to hit 101%!! So, naturally I need to scale back a bit. But I was wondering… it seems in the original image mode patches, the image files are duplicated across many patches. Total newb to Pygame, but its this necessary? Is it possible to haver one single ‘images’ folder and point the patch to it?
Any other suggestions for managing memory?


It would be possible to have the images in a central location, but each mode would still load them into memory on their own, so the memory usage would be the same. To share those images in memory among modes is more complicated, and might involve hacking the underlying system. There is the option of reading images right from disk and blitting them to the screen, this approach would save memory because they are not loaded into RAM…


So, just to confirm - the ITC loads all modes into RAM at start up?


yep, they all get loaded into RAM memory.


Thank you! This idea of “reading images right from disk and blitting them to the screen” - is this a work in progress? :wink:
I would use smaller sized files for this, and load the full 1280x720 images into ram. Just starting to get my Pygame chops…


hmm, looks like there isn’t a specific way to stream from disk, you still have to load it into a variable, but the difference would be instead of loading many images into an array in the setup() section of the mode, it could just load them as it needed in draw() :

img = pygame.image.load('first-image.png')
# replace img with new image
img = pygame.image.load('second-image.png')

so this would draw 2 images on the screen, but only require memory for one.


Do you know yet if there is any processing performance impact from this method?


probably! the program will block while the image file is loading… I haven’t tried it on ETC, only on other computers.


Right on, makes perfect sense. I appreciate all these great answers! And I apologize ahead of time, because I have so many other questions, but I promise to be good about checking docs and other posts first.

Would a hi-speed thumb drive make a difference in this context? Are the USB ports version 2 or 3?


USB jacks are version 2. A hi-speed drive would probably help, but not definitively. Those speed measurements might be for contiguous blocks, or whatever method gives the best results! For example reading a single 4GB file would be faster on a “hi-speed” drive, but reading 4,000 1MB files might not be any faster.


Awesome. This paints a more detailed picture for me now, so thank you! I can’t wait to dig in deeper. :wink:


What is the storage of the ETC?

I’ve just reached 101% and had patches stop working when I’ve only used 87 MB?

Quite confused by this.



is this 87 MB used on disk or in RAM? when PyGame loads images it converts them to bitmaps which might take up significantly more memory in RAM than the image files on disk (which might be compressed as jpeg or png or gif)

There is 512 MB system memory, but about half of that is used by underlying OS. usually keeping RAM usage under 200 MB is a good plan. to get an idea of memory usage of each image you can do: num pixels height * num pixels width * 4 bytes per pixel = total bytes.


Depending on what type of images you want, you can get better performance by avoiding 24-bit resolution on JPEG or PNG images. Going 8-bit with 256 colors may not work as well with photographic images, but works quite acceptably for illustrations and artwork.


87MB on my USB stick. I don’t even have all the modes on there so it’s a
bit. disappointing that it’s full…?


Did you read what Oweno said? 87MB does not necessarily translate to the CPU hit. What happens if you remove all the image modes and try again?


yes, I read it. as I said that’s on the disc. as far as I know there’s no
way to see how much RAM is used…? anyway I sized down my photos so at
least everything works now
even though I’m still at 101%


Going with a reduced color palette will help too. Instead of 24-bit color (which most jpeg/png are) try 16, or 8-bit. From what I’ve tried, this actually does more to reduce load than the image size.