News for hackers. Stuff that matters.
Re:Stop Memsetting Structures by a_t48 on Saturday April 27, 2019 @04:20PM (#19767413)
It depends. It was common case for years in games to just cast your networked data to an array and send over the network. Nowadays it's much more in fashion to pick a serialization library to sit in between, as PCs are faster. But one might choose not to depending on the problem space. Embedded devices might not have the spare cycles or the space for a full serialization library.

So...you're not wrong, but it's basically the same reason people use C over something with more ergonomics.

Edit: the last time I wrote a networking library, I also just cast to raw structures, mainly because it was less work (didn't want to integrate a serialization library on both sides of the link). This was fine for a while (and very fast), but also hid some bugs in the protocol, and made sending arrays of data very ugly. Eventually we put protobuf on top, and things ended up much nicer.

Re:Stop Memsetting Structures by DaiPlusPlus on Saturday April 27, 2019 @04:26PM (#19767446)
How does sending raw memory to the socket work if you have a struct filled with pointers?
Re:Stop Memsetting Structures by mehrdadn on Saturday April 27, 2019 @04:27PM (#19767449)
I think they simply don't do that with structs that contain pointers?
Re:Stop Memsetting Structures by a_t48 on Saturday April 27, 2019 @04:46PM (#19767531)
Indeed, this. If you have data with pointers, you either need to flatten (read: copy) your structure into something appropriate for structuring, or just get a proper serialization layer.
Re:Stop Memsetting Structures by repsilat on Saturday April 27, 2019 @05:55PM (#19767866)
I guess there could be some fun workarounds with ptrdiff_t instead of pointers. "My child is 1000 bytes that way in memory" etc.
Re:Stop Memsetting Structures by a_t48 on Saturday April 27, 2019 @06:24PM (#19768006)
That's a pretty classical file serialization trick to pack a bunch of heterogeneous data in one file. A header/manifest starting the file, with an array of names, offsets, and sizes.
Re:Stop Memsetting Structures by blattimwind on Saturday April 27, 2019 @09:02PM (#19768657)
Actually works somewhat well for mmap'ed access, too, by using a macro or function to "dereference" "pointers" (offsets).
Re:Stop Memsetting Structures by a_t48 on Saturday April 27, 2019 @10:38PM (#19768951)
Or even an OffsetPtr class with overloaded arrow and dereference operator, if you swing that way. :)
Re:Stop Memsetting Structures by DaiPlusPlus on Sunday April 28, 2019 @08:59AM (#19770921)
What’s the runtime performance of that in-practice? Does x86, x64 and ARM have support for relative offset pointers without any performance impact? And do compilers use them?
Re:Stop Memsetting Structures by blattimwind on Sunday April 28, 2019 @12:38PM (#19772073)
Yes, address generation can at the very least do [reg + constant], and on x86, much much more. These are bread and butter optimizations constantly used by compilers all over the place, because this is how field access works.