1

Default byte order of QDataStream is BigEndian, according to its documentation. AFAIK this means that written data on a little-endian platform is converted from little to big and read data is converted from big to little.

Most platforms supported by Qt, especially x86/x64, are little-endian. This link states Qt's CI doesn't even include any big-endian devices. This would mean that the default configuration of QDataStream requires lots of endianness conversions on Qt's major platforms - which would be pretty sub-optimal.

Did I miss something obvious? If not, why didn't Qt use LittleEndian as a default to support major platforms more efficiently?

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
  • Same could be argued for the network byte order (which is also BE IIRC). Presumably, they've decided to follow in their suite? – Super-intelligent Shade Oct 05 '21 at 22:59
  • @InnocentBystander Is there something like "the network byte order"? I would have expected byte order in protocols to vary as well. What protocols do you have in mind? – Silicomancer Oct 05 '21 at 23:15
  • 1
    The historic [IETF RFC 1700](https://datatracker.ietf.org/doc/html/rfc1700) states "*The convention in the documentation of Internet Protocols is to express numbers in decimal and to picture data in "big-endian" order*". A protocol is free to use another endianess and even a variable one but many historically used the big-endian order because of that. Big-endian benefits from being easier to debug while being a bit less efficient on little-endian architectures like the dominant x86-64 one. – Jérôme Richard Oct 05 '21 at 23:30
  • @Silicomancer yes. Just google "network byte order". – Super-intelligent Shade Oct 06 '21 at 00:55
  • 1
    Also the x86 instruction set knows has a command for this - BSWAP so even it's not optimal it's for sure not that slow. – chehrlic Oct 06 '21 at 18:31
  • Not to mention it can be vectorized in some case resulting in a cheap byte swap (typically using sse/avx shuffles or combine/permute instruction in neon/altivec) – Jérôme Richard Oct 06 '21 at 22:59

0 Answers0