I am curious why does my game use
80 MB of memory.
I am using
VS 2015 and when I launch my game I see that my process memory is at
88 MB min.
Its weird. I am using like
30 textures 30 sprites.In those 30 textures I load images from my folder called "images". These images all together use
80 KB.
All these textures are then loaded in my 30 sprites.
I create textures as pointers. This way :
sf::Texture* tx_wall = new sf::Texture();
tx_wall->loadFromFile("images/wall.bmp");
//MAIN GAME LOOP HERE
//.
//.
//.
// END OF GAME LOOP
delete tx_wall;
I also noticed that sometimes when I start game process memory jumps to 110 MB and stays at that point. If I launch my game again 3 times (sometimes only once) it goes back to
88 MB.If I remove 4 images (They take
16 KB) from my folder so textures are not able to open them, it reduces my process memory by 20 MB so now my memory usage is
60 MB.
These 4 specific images only. If I remove any other image it Memory usage stays the same.
These images are only used by my custom class which look like this :
my_button.h#pragma once
#ifndef MY_BUTTON_H
#define MY_BUTTON_H
#include <SFML\Graphics.hpp>
class Button {
private:
float x, y;
sf::RectangleShape size;
sf::Sprite *my_sprite;
sf::Texture *my_texture;
sf::Texture *my_press_texture;
bool me_pressed = false;
public:
Button(const sf::Texture& txr, const float& x_spawn, const float& y_spawn);
Button(const sf::Texture& txr,const sf::Texture& txr_p, const float& x_spawn, const float& y_spawn);
~Button();
sf::RectangleShape getSize();
sf::Vector2f getPosition();
void setPosition(const float& x_spawn, const float& y_spawn);
void setTexture(const sf::Texture& txr);
void setPressTexture(const sf::Texture& txr);
void pressed(bool p);
bool is_pressed();
bool is_hovered(const sf::Vector2i& mouse_pos);
sf::Sprite getSprite();
};
#endif
and this is the
my_button.cpp#include "my_Button.h"
Button::Button(const sf::Texture& txr, const float& x_spawn, const float& y_spawn){
x = x_spawn;
y = y_spawn;
my_sprite = new sf::Sprite(txr);
my_texture = new sf::Texture(txr);
my_sprite->setPosition(x, y);
size.setSize(sf::Vector2f(my_sprite->getGlobalBounds().width, my_sprite->getGlobalBounds().height));
}
Button::Button(const sf::Texture& txr, const sf::Texture& txr_p, const float& x_spawn, const float& y_spawn) {
x = x_spawn;
y = y_spawn;
my_sprite = new sf::Sprite(txr);
my_texture = new sf::Texture(txr);
my_press_texture = new sf::Texture(txr_p);
size.setSize(sf::Vector2f(my_sprite->getGlobalBounds().width, my_sprite->getGlobalBounds().height));
}
Button::~Button() {
delete my_sprite;
delete my_texture;
delete my_press_texture;
}
sf::RectangleShape Button::getSize() {
return size;
}
sf::Vector2f Button::getPosition() {
return sf::Vector2f(x, y);
}
void Button::setTexture(const sf::Texture& txr) {
delete my_sprite;
delete my_texture;
my_texture = new sf::Texture(txr);
my_sprite = new sf::Sprite(txr);
}
void Button::setPressTexture(const sf::Texture& txr) {
my_press_texture = new sf::Texture(txr);
}
bool Button::is_hovered(const sf::Vector2i& mouse_pos) {
if (my_sprite->getGlobalBounds().contains((float)mouse_pos.x, (float)mouse_pos.y)) {
return true;
}
return false;
}
sf::Sprite Button::getSprite() {
return *my_sprite;
}
void Button::setPosition(const float& x_spawn, const float& y_spawn) {
x = x_spawn;
y = y_spawn;
my_sprite->setPosition(x, y);
}
void Button::pressed(bool p) {
me_pressed = p;
if (me_pressed) {
my_sprite->setTexture(*my_press_texture);
}
else {
my_sprite->setTexture(*my_texture);
}
}
bool Button::is_pressed() {
return me_pressed;
}
I have 2
buttons which use these 4 images (2x idle and 2x pressed). If I remove them memory goes down by
20 MB.the 2
BUTTONS :
Button *cmd_continue = new Button(*texture_continue, popup_win.getPosition().x+16, popup_win.getPosition().y + popup_win.getSize().y - 48);
Button *cmd_leave = new Button(*texture_leave, popup_win.getPosition().x + (popup_win.getSize().x - 16 - texture_leave->getSize().x), popup_win.getPosition().y + popup_win.getSize().y - 48);
cmd_continue->setPressTexture(*texture_continue_p);
cmd_leave->setPressTexture(*texture_leave_p);
//MAIN GAME LOOP DOWN THERE
And I have other 4
Buttons (my class). If I remove images from folder that they used for their textures Process MEMORY STAYS THE SAME.
What is happening here ? Any ideas ?
I am using :
VS 2015
WIN 10 x64
RAM 6GB
CPU Intel Core 2 Duo E8600
GPU AMD 5670HD 1 GBOther variables I use they shouldn't take that much memory. My Map is presented in
2D char vector which is
39*50. That is
0,23 KBIf I do
sf::Texture::getMaximumSize()
this returns 16384