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

Author Topic: Loading from memory  (Read 1652 times)

0 Members and 1 Guest are viewing this topic.

svrtgujbhk

  • Newbie
  • *
  • Posts: 20
    • View Profile
Loading from memory
« on: June 05, 2011, 05:55:41 pm »
After loading from memory, does SFML assume possession of the buffer data, or is it safe to delete it? The documentation says nothing, which leads me to assume it can be deleted, but I want to make sure.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Loading from memory
« Reply #1 on: June 05, 2011, 06:05:38 pm »
If you delete the image then you no longer can use it.

What do you mean by delete exactly ?
SFML / OS X developer

svrtgujbhk

  • Newbie
  • *
  • Posts: 20
    • View Profile
Loading from memory
« Reply #2 on: June 05, 2011, 06:13:00 pm »
I mean like this:

Code: [Select]

char* buffer = ...;
size_t size = ...;

sf::Font font;
font.LoadFromMemory(buffer, size);

// Is it safe for me to delete the buffer now?
free(buffer);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Loading from memory
« Reply #3 on: June 05, 2011, 06:59:34 pm »
This is true for images or sound buffers for not for fonts. A font cannot be 100% loaded from its source (it may define thousands of characters, and I don't include the various styles and sizes). So the font data must be kept in memory as long as the font is used.
Laurent Gomila - SFML developer

svrtgujbhk

  • Newbie
  • *
  • Posts: 20
    • View Profile
Loading from memory
« Reply #4 on: June 05, 2011, 07:18:42 pm »
Thank you! I think you should add this bit of information to the documentation. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Loading from memory
« Reply #5 on: June 05, 2011, 08:30:03 pm »
It's already done in the SFML 2 documentation.
Laurent Gomila - SFML developer

 

anything