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

Author Topic: Texture saved in Ram  (Read 2562 times)

0 Members and 1 Guest are viewing this topic.

M3TJ20

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Texture saved in Ram
« on: June 19, 2016, 03:42:37 pm »
Hey, is it possible to keep a loaded texture saved in the RAM?
I created a global class/object and tried to save the texture in it.
But if it doesnt work, if i leave the main function...

Is there a way to keep the texture in the RAM?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Texture saved in Ram
« Reply #1 on: June 19, 2016, 04:35:23 pm »
When you leave main your program terminates and the kernel reclaims all its memory. If you want something to persist beyond that point you have to store it somewhere else - like sysv shared memory, a file or elsewhere.

Limeoats

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Limeoats
Re: Texture saved in Ram
« Reply #2 on: June 28, 2016, 04:05:38 pm »
Hey, is it possible to keep a loaded texture saved in the RAM?
I created a global class/object and tried to save the texture in it.
But if it doesnt work, if i leave the main function...

Is there a way to keep the texture in the RAM?

Leaving the main function ends your program, and all resources related to your program are released. This means that even if you have a global class that stores a texture, its memory will be freed and will no longer have your texture once you leave main.

I don't see the benefit of saving a texture in some kind of database. You should just load them each time the program starts.

DragonDePlatino

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Texture saved in Ram
« Reply #3 on: June 30, 2016, 05:23:33 am »
Let's say M3TJ20 has a texture that stores the Fog of War of a level on a per-pixel basis. That's something that would be needed to be saved and loaded again later. To do that, export your texture like so:

Code: [Select]
texturename.copyToImage().saveToFile("filename.png");
And then load it again with:

Code: [Select]
sf::Texture newtexture;
newtexture.loadFromFile("filename.png");

And like Limeoats said, do not save a texture in your database if it is going to be the same every time the user runs the program. This should only be done for user-made textures. Also, the user will be able to open the file and edit it. You would need to encrypt it somehow if you don't want the user doing this.