SDLnets byteswapping

SDLnet uses the functions SDLNet_Write16/32 to convert data to network
byte order. Now these functions use a right shift to get each byte and
place it into nbo in an array. Shouldn’t these just be macros like htonl()
and such? Because if a machines data format doesn’t need to be converted
then all this shifting is wasted time. I think just using the standard
htonl() type macros would be better, and if they are not defined already
just define them in the SDLnet.h, or is this not so?

http://www.mongeese.org

Mensaje citado por: Garrett Banuk :

SDLnet uses the functions SDLNet_Write16/32 to convert data to
network
byte order. Now these functions use a right shift to get each byte
and
place it into nbo in an array. Shouldn’t these just be macros like
htonl()
and such? Because if a machines data format doesn’t need to be
converted
then all this shifting is wasted time. I think just using the
standard
htonl() type macros would be better, and if they are not defined
already
just define them in the SDLnet.h, or is this not so?

It isn’t so simple, as you should know with what endian the data was
generated. So you need an extra field.
While if use SDLNet_Write16/Read16, you always do it, no matter what
endian you have.

http://www.arianne.cx

Well there is a #define in SDL which states what the machine endianess
is, SDL_LIL_ENDIAN, SDL_BIG_ENDIAN I think. I added some more functions to
sdlnet.c so if the machine is BIG endian, the functions just copy the data
without shifting. It speeds things up a bit.

http://www.mongeese.orgOn Fri, 2 Feb 2001, MIGUEL ANGEL BLANCH LARDIN wrote:

Mensaje citado por: Garrett Banuk :

SDLnet uses the functions SDLNet_Write16/32 to convert data to
network
byte order. Now these functions use a right shift to get each byte
and
place it into nbo in an array. Shouldn’t these just be macros like
htonl()
and such? Because if a machines data format doesn’t need to be
converted
then all this shifting is wasted time. I think just using the
standard
htonl() type macros would be better, and if they are not defined
already
just define them in the SDLnet.h, or is this not so?

It isn’t so simple, as you should know with what endian the data was
generated. So you need an extra field.
While if use SDLNet_Write16/Read16, you always do it, no matter what
endian you have.

http://www.arianne.cx

Mensaje citado por: Garrett Banuk :

Well there is a #define in SDL which states what the machine
endianess
is, SDL_LIL_ENDIAN, SDL_BIG_ENDIAN I think. I added some more
functions to
sdlnet.c so if the machine is BIG endian, the functions just copy
the data
without shifting. It speeds things up a bit.

http://www.mongeese.org

Would you mind to share that piece of code?