skip to Main Content

I notice there is a macro uint4korr in the MySQL/MariaDB source code.

include/byte_order_generic.h

I merely understand this macro is correlated with byte order. But I looked for the comments about this macro, found nothing. I don’t know the meaning of the suffix korr. What does the abbreviation express?

I want to know why the code implements like this? What are the effects on different platforms?

2

Answers


  1. "korr" is an abbreviation for "Korrekt" of the phonic and meaning equivalent of the English word "Correct".

    The purpose of the code is to provide a uniform byte order of storage and communication components so the storage files are portable between different endian architectures without conversion, and the client/server communication doesn’t need to know which endian the other architecture is.

    Login or Signup to reply.
  2. I believe that the related Swedish verb is korrigera, to correct. uint4korr() is kind of the opposite of ntohl(), because it will swap the bytes on a big-endian architecture and not little-endian.

    Somewhat related to this, the InnoDB storage engine stores its data in big-endian byte order, so that a simple memcmp() can be used for comparing keys. (It also inverts the sign bit of signed integers due to this.) The InnoDB function mach_read_from_4() is basically ntohl() combined with a 32-bit load via an unaligned pointer. Recent versions of GCC and clang impress me by translating that into the IA-32 or AMD64 instructions mov and bswap or simply movbe.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search