[Y-devel] Proposal for a minor change in the Y-protocol (Modified by Augie Fackler)

Tim Wood tim at flamingpenguin.co.uk
Thu Apr 15 16:43:26 BST 2004


Hi,

Augie Fackler wrote:
>> <snip>
>> "Let's break the protocol on platforms without 4-byte memory alignment
>> to work around the possibility of code being written by morons in the
>> future"? That's not a very compelling argument. You have to be really
>> stupid to write socket code with alignment issues.
> 
> Pardon my potential ignorance here, but *how* does this break the 
> protocol on platforms w/o 4-byte alignment versus having no alignment at 
> all? Perhaps I don't fully understand what you mean by alignment...

Seems to me, the main point is that not all platforms align on 4byte 
boundarys. Some processors have different alignment requirements, for 
instance, 64bit address pointers on an AMD-64 should be aligned on an 
8byte boundary (only example I can think of right now). I expect more 
examples could be found, especially in the case of 64bit processors.

Alignments should really be left to the compiler, as far as possible - 
that way they will automatically be correct on all platforms, /after/ 
the data is unpacked from the message. Considering alignment in the 
messages would introduce a hardware dependency (i.e. non-4-byte-aligned 
processors would get mis-aligned data, and have to behave differently 
than 4-byte-aligned processors). However the same is true for endianess, 
one of the two types will have to fix the endianess - the other won't.

Of course it doesn't /break/ the protocol, since non-4-byte-aligned 
platforms could just work around it, presumably at some degraded 
performance - they would have had to do that with the un-aligned 
protocol anyway. But it seems to me, that it doesn't buy that much 
either - and might lead to people writing code which doesn't fix the 
alignment (or incorrectly "fixes" the alignment) when compiled on an 
unexpected processor (i.e less portable code). Perhaps it is better to 
keep it simple?

I don't think its equivalent to sending in host endianess, since no one 
suggested sending host alignment. But some fixed guess at the most 
probable alignment - the same from all hosts. Still, how good is the 
guess - especially if you take the long view of the protocol (what will 
alignment be like in 10 years time?).

However, some protocols do pad, for instance I think IP headers are 
padded to end on a 4-byte boundary, and none of its fields cross a 
4-byte boundary (except options). It also provides a mechanism to align 
option fields on 4-byte boundaries (the no-op option 00000001). But 
alignment of options seems to be optional ;-).

*shrugs* /goes back to lurking

Tim



More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved