4 ms·
>data structures already have to sit in memory looking a certain way, why can't we just squirt that on the wire instead of some fancy bespoke type-length-value
by jackmott 10y ago
>data structures already have to sit in memory looking a certain way, why can't we just squirt that on the wire instead of some fancy bespoke type-length-value struct?
In C/C++ ya can!
When making games in college that is exactly what we did. Take the struct, dump it into the socket. I was rather shocked when trying to recreate the same system in C#. "I can't? I CAN'T?"
- paulddraper 10y agoWell...that's kind of the point of C#. Enforced memory safety. Use C if that's not what you want. Don't hammer with a screwdriver.
- QuercusMax 10y agoThat's an absolutely terrible idea if you want any kind of forward / backward compatibility. Just about any system is better than dumping structs over the network, once you're dealing with a system that can evolve.
- izacus 10y agoYeah, I once had to write an Android / Desktop C++ implementation of such an API that was squirting iOS datastructures over socket. The API was built by a programmer who didn't know what endianess (or size of the structs) was. That was a special kind of hell :/
- heywire 10y agoYou might be surprised just how many successful applications simply dump a packed struct to disk as a serialization format (or even transmit it over the wire). If the operating environment (OS/hardware) is known to be of a certain type, endianness is not a concern.
- QuercusMax 10y agoIt's not just endianness; it's about maintainability. If you ever think you might change the struct, EVER, you need to worry about these things.