SFML community forums
Help => Graphics => Topic started by: Furkanzmc on March 06, 2014, 04:28:20 pm
-
Hello.
I'm relatively new to game development and I'm making a small game with a number of images which only holds 119 MB on disk. But when I load them in the game, the memory usage of the game skyrockets to 862 MB!
Are there any solutions to fix this issue?
Thanks in advance!
Solution:
The problem was indeed with the images. I reduced the resolution of the images and everything is fine now. It wasn't a code problem.
-
The problem is on the line 42...no seriously, without code we can't do anything. My best guess is that you load the images multiple time in memory.
-
Images on disk are encoded using an image file format, they are more (jpeg) or less (bmp) compressed. After being loaded to RAM, they are decoded and stored as pure 32-bits RGBA values. So don't expect the sizes to be the same, they are totally unrelated.
-
Taking into account what Laurent said, the amount increasing so much when loaded into RAM implies that you use a decent compression. 119mb of compressed image data seems like an excessive amount for a small game.
First, you should try reducing the number of images. If your player can e.g. use a custom color for the character and you created 100 images in different colors, try using one image for the "naked" character and a second one for the colored overlay, which is drawn on top with the help of sf::Sprite::setColor (http://www.sfml-dev.org/documentation/2.1/classsf_1_1Sprite.php#a14def44da6437bfea20c4df5e71aba4c).
Second, if you really need all the images you still probably don't need them all at once. Load only the textures that you need for the current level, free the resources before loading the next level, if that makes any sense for your game.