SFML community forums

Bindings - other languages => C => Topic started by: Jebbs on December 08, 2012, 10:31:54 am

Title: Finding the size of things!
Post by: Jebbs 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!
Title: Re: Finding the size of things!
Post by: eXpl0it3r 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? ;)
Title: Re: Finding the size of things!
Post by: Nexus 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).
Title: Re: Finding the size of things!
Post by: Jebbs 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?
Title: Re: Finding the size of things!
Post by: Laurent on December 08, 2012, 12:18:12 pm
createFromMemory loads the resource from a file in memory.

To duplicate a texture, use sfTexture_copy.
Title: Re: Finding the size of things!
Post by: Jebbs 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)
Title: Re: Finding the size of things!
Post by: Laurent on December 08, 2012, 01:48:42 pm
Ah, sorry this function should definitely take a const pointer. I'll fix that.

EDIT: done ;)