SFML community forums
Bindings - other languages => C => Topic started 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!
-
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? ;)
-
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).
-
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?
-
createFromMemory loads the resource from a file in memory.
To duplicate a texture, use sfTexture_copy.
-
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)
-
Ah, sorry this function should definitely take a const pointer. I'll fix that.
EDIT: done ;)