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

Author Topic: Finding the size of things!  (Read 4335 times)

0 Members and 1 Guest are viewing this topic.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Finding the size of things!
« on: December 08, 2012, 10:31:54 am »
Hey guys,

In the various createFromMemory functions, one of the parameters is the size of the object in bytes. How would one go about finding the size of the object so that they could enter in the correct size to use these functions?

Thanks!
DSFML - SFML for the D Programming Language.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Re: Finding the size of things!
« Reply #1 on: December 08, 2012, 10:47:41 am »
Well to load things from memory you need them to be in memory and for them to be in memory you at some point have to allocate that memory and while allocating you have to specify the size, thus since you allocate memory with a certain size you should already know the size and can pass it to the function.

What exactly are you trying to do? ;)
« Last Edit: December 08, 2012, 10:49:29 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Finding the size of things!
« Reply #2 on: December 08, 2012, 10:48:00 am »
When you load something into memory, you already know its size, because you have to allocate the correct amount of memory. At least if you do it meaningfully (and don't just allocate a fixed size buffer with an arbitray magic number as size).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Finding the size of things!
« Reply #3 on: December 08, 2012, 11:17:42 am »
Here is an example of what I mean.

sfTexture* someTexture = sfTexture_createFromFile("some image.png", null);


How can I figure out the size of someTexture? I'm not doing the allocating myself.


I'm working on some binding stuff at the moment. My current issue relates to some stuff I'm doing with the Font class. My Font will return a Texture representation with the function getTexture just like sf::Font, but sfFont_getTexture returns a const pointer to a sfTexture. I didn't want to cast away the const, so I thought I would make a new sfTexture using sfTexture_createFromMemory, and then I came to where I am now.

In any case, I have experienced this elsewhere when playing with my binding and I now feel like it is something I should make sure i can handle.

Any suggestions?
DSFML - SFML for the D Programming Language.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Finding the size of things!
« Reply #4 on: December 08, 2012, 12:18:12 pm »
createFromMemory loads the resource from a file in memory.

To duplicate a texture, use sfTexture_copy.
Laurent Gomila - SFML developer

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Finding the size of things!
« Reply #5 on: December 08, 2012, 01:33:37 pm »
Ah, well I was totally mistaken on that then. I didn't even make the connection that it was a file in memory, not an object in memory. That said, I can't call sfTexture_copy with a const sfTexture pointeras I get compiler crankiness.

Specifically:
 Error: function pointer sfTexture_copy (sfTexture* texture) is not callable using argument types (const(sfTexture)*)

(DMD compiler for the D language)
DSFML - SFML for the D Programming Language.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Finding the size of things!
« Reply #6 on: December 08, 2012, 01:48:42 pm »
Ah, sorry this function should definitely take a const pointer. I'll fix that.

EDIT: done ;)
« Last Edit: December 08, 2012, 01:54:11 pm by Laurent »
Laurent Gomila - SFML developer

 

anything