On 04/11/11 11:35, Kjell Rilbe wrote:
> Den 2011-04-11 09:19 skrev Alex Peshkoff såhär:
>> I'm far not sure everything is so fine with that structure/class. Look here:
>>      unsigned
>> blrLength;
>>
>>      const unsigned char* blr;
>> Pointer (8-bytes object) is placed after integer (4-bytes object). C
>> language has a requirement to align it on 8-bytes boundary, but what
>> about others? I't quite possible that some other language will try to
>> save memory. The result is obvious - segfault when we use such structure.
> 1. This is a doc issue more than anything. There's always a workaround, 
> e.g. insering dummy fields in a language that uses "packed" 
> recs/structs. Just make sure you document the binary format complete 
> with alignment/padding.

That's possible, I think. But not too good.
The main disadvantage that this layout may probably differ for different
hardware.
And what - with every new port rewrite/review a piece of documentation?

> 2. If I'm not mistaken most languages support a "packed" directive that 
> tells the compiler to not align/pad the struct. Delphi does. But I doubt 
> it's possible to do the other way around: tell a compiler to pad/align 
> to N bytes. So, perhaps the most compatible way is to use packed structs 
> everywhere. 

That's impossible at least for RISC machines.

> On the other hand, this will probably induce a performance 
> hit - that's why alignment is used at all.

Yes, it's known fact that some intel CPUs have serious performance hit
when working with misaligned data.


------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to