Images and Memory Usage

Hi People…

Just wanted to get a handle on a preferred way of handling images. In my game I currently have 8 different backgrounds I use at various stages during my game, at the moment I currently create a cache of the 8 images (752x512 JPG ~ 150KB) at start up. But I am beginning to think, convinced by profiling, that I am eating up unnecessarily large amounts of ram - Some of the images aren’t going to be used (should I use lazy-loading perhaps?).

So my question is, should I switch to loading the image when I require it in the game?
Thus only having 1 buffered image at anyone time for the background? A pause in the game whilst it loads the image, for the level, is fine. I am just thinking - with this method I am going to incur more GC’s due to rotation of different backgrounds.

Anyone have any thoughts? Or is this just a straight trade off?

Cookie

Whichever floats your boat. Getting back 7x150KB isn’t going to make a difference but if you strive for least memory usage, go for it. If you want the best user experience, those extra 1.05MB aren’t going to hurt :wink:

Yeah, looks that way.

Also as a side thing, wouldn’t it be more than 7*150KB as the BufferedImage object would contain an uncompressed byte[], post decode, of the image? - I will profile again later looking for byte[]

Usually when you start looking at these kind of optimizations you’ll never stop and the game will linger instead of being finished :wink:

Personally I’d consider (if it is a small scale applet/webstart game) to stream the new pictures from the server the first time they are needed, that’ll decrease the initial loading time with something like 10-20 seconds for people with “normal” connections.

Mike

Yes that is very true… You can’t profile images out of existence.

Streaming is a great idea, I already logically group my images in different jars to a;low for caching…

I guess moving on to my other hotspots :slight_smile:

Oh yeah you’re using JPG, it’s gonna be more than 150KB.

However remember and don’t forget this important quote: