Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Excessive Memory Usage Problem  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

Furkanzmc

  • Newbie
  • *
  • Posts: 13
    • View Profile
[SOLVED] Excessive Memory Usage Problem
« 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.
« Last Edit: March 18, 2014, 09:31:41 am by Furkanzmc »

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Excessive Memory Usage Problem
« Reply #1 on: March 06, 2014, 04:48:36 pm »
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.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Excessive Memory Usage Problem
« Reply #2 on: March 06, 2014, 04:52:27 pm »
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.
Laurent Gomila - SFML developer

Daerst

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Excessive Memory Usage Problem
« Reply #3 on: March 07, 2014, 01:59:44 pm »
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.

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.

 

anything