by codesuki on 9/16/24, 9:16 AM with 58 comments
by LegionMammal978 on 9/20/24, 8:53 PM
by iscoelho on 9/20/24, 9:46 PM
- mmap/io_uring/drivers and additional "zero-copy" code implementations require consideration about byte order.
- filesystems, databases, network applications can be high throughput and will certainly benefit from being zero-copy (with benefits anywhere from +1% to +2000% in performance.)
This is absolutely not "premature optimization." If you're a C/C++ engineer, you should know off the top of your head how many cycles syscalls & memcpys cost. (Spoiler: They're slow.) You should evaluate your performance requirements and decide if you need to eliminate that overhead. For certain applications, if you do not meet the performance requirements, you cannot ship.
by chasil on 9/20/24, 8:17 PM
"htonl, htons, ntohl, ntohs - convert values between host and network byte order"
The cheapest big-endian modern device is a Raspberry Pi running a NetBSD "eb" release, for those who want to test their code.
by rwmj on 9/20/24, 8:34 PM
He even has an example where he just pushes the problem off to someone else "if the people at Adobe wrote proper code to encode and decode their files", yeah hope they weren't ignoring byte order issues.
by genpfault on 9/20/24, 8:14 PM
Original thread w/104 comments:
by AstralStorm on 9/20/24, 8:50 PM
And do not define any data format to be big endian anymore. Deine it as little endian (do not leave it undefined) and everyone will be happy.
by Laremere on 9/20/24, 9:02 PM
Given a reader (file, network, buffers can all be turned into readers), you can call readInt. It takes the type you want, and the endianess of the encoding. It's easy to write, self documents, and it's highly efficient.
by ultrahax on 9/20/24, 9:48 PM
by benlivengood on 9/20/24, 10:02 PM
by _nalply on 9/21/24, 8:09 AM
Rust, for example has from_be_bytes(), from_le_bytes() and from_ne_bytes() methods for the number primitives u16, i16, u32, and so on. They all take a byte array of the correct length and interpret them as big, little and native endian and convert them to the number.
The first two methods work fine on all architectures, and that's what this article is about.
The third method, however, is architecture-dependent and should not be used for network data, because it would work differently and that's what you don't want. In fact, let me cite this part from the documentation. It's very polite but true.
> As the target platform’s native endianness is used, portable code likely wants to use from_be_bytes or from_le_bytes, as appropriate instead.
by fracus on 9/20/24, 9:55 PM
by nativeit on 9/22/24, 5:21 PM
As a non-SWE, whenever I see checkboxes to enable options that maximize compatibility, I often assume there’s an implicit trade-off, so if it isn’t checked by default, I don’t enable such things unless strictly necessary. I don’t have any solid reason for this, it’s just my intuition. After all, if there were no good reasons not to enable Mac compatibility, why wouldn’t it be the default?
Edit: spelling error with “implicit”
by e4m2 on 9/20/24, 10:05 PM
by wmf on 9/20/24, 9:59 PM
Also, a lot of comments in this thread have nothing to do with the article and appear to be responses to some invisible strawman.
by nuancebydefault on 9/20/24, 8:42 PM
by eternityforest on 9/20/24, 10:53 PM
by wakawaka28 on 9/21/24, 12:15 AM
by wiredfool on 9/20/24, 9:14 PM