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

Author Topic: sfIpAddress size  (Read 5386 times)

0 Members and 1 Guest are viewing this topic.

Jeanne-Kamikaze

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • ShellBlade
sfIpAddress size
« on: November 07, 2012, 04:19:44 pm »
sfIpAddress represents an IPV4 address according to the documentation, yet it is 16 bytes long (at least on x86):

typedef struct
{
    char address[16];
} sfIpAddress;

On the other hand, an IpAddress is 4 bytes:

class SFML_NETWORK_API IpAddress
{
    ...
private :

    ////////////////////////////////////////////////////////////
    // Member data
    ////////////////////////////////////////////////////////////
    Uint32 m_address; ///< Address stored as an unsigned 32 bits integer
}

Shouldn't sfIpAddress be 4 bytes as well, or am I missing something ?
« Last Edit: November 07, 2012, 04:24:14 pm by jeannekamikaze »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfIpAddress size
« Reply #1 on: November 07, 2012, 04:25:00 pm »
I don't remember why, but there must be a good reason.

Is it really important anyway?
Laurent Gomila - SFML developer

Jeanne-Kamikaze

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • ShellBlade
Re: sfIpAddress size
« Reply #2 on: November 07, 2012, 04:27:12 pm »
Maybe you were thinking IPV6. And no, it's not really important, unless the C code accesses a byte other than the first 4 of course. It also looks confusing in my opinion.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfIpAddress size
« Reply #3 on: November 07, 2012, 05:13:15 pm »
You misunderstand what is stored in sfIpAddress. It's not the 32-bits representation of the address, it's its string form ("xxx.xxx.xxx.xxx" -> 16 characters with the ending \0).

Now I remember why I did it this way: when you call sfIpAddress_toString() I can return a direct pointer to this member. Otherwise I would have to allocate a memory area, and let the caller manage its lifetime. Would be very inconvenient.
Laurent Gomila - SFML developer

Jeanne-Kamikaze

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • ShellBlade
Re: sfIpAddress size
« Reply #4 on: November 07, 2012, 05:30:36 pm »
Ah! Good to know then. Maybe state that in the docs ?

Jeanne-Kamikaze

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • ShellBlade
Re: sfIpAddress size
« Reply #5 on: November 07, 2012, 05:37:46 pm »
But wait, so every time I use stuff like sfUdpSocket_send it's gonna parse the string address into a dword ?

Edit: This is indeed the case. Why not cache the dword in sfIpAddress then to avoid having to reparse the string on every call ?
« Last Edit: November 07, 2012, 05:44:20 pm by Jeanne-Kamikaze »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfIpAddress size
« Reply #6 on: November 07, 2012, 07:26:40 pm »
Quote
Maybe state that in the docs ?
You don't need to do that, although it's public, you should never access it directly. The only API that you should know is the set of sfIpAddress_xxx functions.

Quote
Why not cache the dword in sfIpAddress then to avoid having to reparse the string on every call ?
Why? Who cares? And don't answer "it's slow" if you haven't tested it seriously ;)
Laurent Gomila - SFML developer

Jeanne-Kamikaze

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • ShellBlade
Re: sfIpAddress size
« Reply #7 on: November 07, 2012, 07:59:39 pm »
Quote
You don't need to do that, although it's public, you should never access it directly. The only API that you should know is the set of sfIpAddress_xxx functions.

True. I'm reimplemeting some of the functions however. For instance, I don't really have to call C to initialise an address to 0. And yes, I can afford the maintenance.

Quote
Why? Who cares? And don't answer "it's slow" if you haven't tested it seriously

I personally don't care, but it's a multimedia library. Real-time systems will be built on it, and as a library provider you should ensure that what you ship runs half decent. It would suck to profile my application only to find out that the bottleneck is in the underlying API, and not because I'm making a bad use of it but simply because it is inherently slow. And no, there aren't any alternatives; SFML is the multimedia library.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfIpAddress size
« Reply #8 on: November 07, 2012, 08:28:53 pm »
Quote
Real-time systems will be built on it, and as a library provider you should ensure that what you ship runs half decent. It would suck to profile my application only to find out that the bottleneck is in the underlying API, and not because I'm making a bad use of it but simply because it is inherently slow.
True. And I'll be glad to change this if someones proves me that it's too slow. But to be honest, I have almost no time to work on SFML itself, and CSFML is only a way to enable other bindings, so its improvement is very low on my task list.
Laurent Gomila - SFML developer

Jeanne-Kamikaze

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • ShellBlade
Re: sfIpAddress size
« Reply #9 on: November 07, 2012, 09:50:55 pm »
When you said

Quote
Now I remember why I did it this way: when you call sfIpAddress_toString() I can return a direct pointer to this member. Otherwise I would have to allocate a memory area, and let the caller manage its lifetime. Would be very inconvenient.

Why ? Can't you make a function that takes a char* and writes the string in there ? No need to allocate anything on the library side.

It's not SFML that needs changing, just CSFML. If you don't have time then I could do it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sfIpAddress size
« Reply #10 on: November 07, 2012, 10:09:04 pm »
Quote
Why ? Can't you make a function that takes a char* and writes the string in there ? No need to allocate anything on the library side.
Yep, I could do that. But the current solution is simpler and safer.
Laurent Gomila - SFML developer

Jeanne-Kamikaze

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • ShellBlade
Re: sfIpAddress size
« Reply #11 on: November 09, 2012, 01:05:15 pm »
Oh well, I forked the project and made the changes there. Took me just 2 minutes :). I'm liking your fromSFMLAddress and toSFMLAddress helpers.