Reputation:
I noticed that FastCGI protocol defines a 7 byte record (data structure used in communication) header with 1 byte padding. Other structures are also padded when necessary. Wondering if this one byte changes anything, I timed 1000000 sequential sends and receivals of 7 and 8-byte buffers, and found out... nothing in particular. Several executions provided data so variable, that not even worth averaging. (testing code)
If i have to send 7-byte data over TCP is it worth it to add one byte, so my sends and reads operate on 8-byte buffer? Where's that coming from and how to know what padding is appropriate? Is it different if socket is Unix file socket, or INET socket? Is it different if sender and recipients are on the same host?
Upvotes: 2
Views: 1451
Reputation: 84169
This goes back to alignment requirements of different architectures, and main purpose here is to minimize data copying that would have to be done on strict-alignment platforms, and taking advantage of faster execution on commodity PC hardware. This is why most low-level protocols like IP and TCP have integers in the headers aligned on 32 or 64-bit boundaries.
Upvotes: 0
Reputation: 10855
No, the padding is not related to the networking.
It is common to see structures defined this way so that they are aligned on a 4-byte boundary (or 8-byte on 64 bit OS). See here for more:
http://en.wikipedia.org/wiki/Data_structure_alignment
Upvotes: 1