[M3devel] platform-independent packing/alignment?

Rodney M. Bates rodney_bates at lcwb.coop
Mon Feb 1 20:52:55 CET 2010



Jay K wrote:
> Let's say I have:
>  
>  
> TYPE FOO = RECORD a: LONGFLOAT; b: UINT32; END;
> TYPE FOOA = ARRAY [0..1] OF FOO;
>  
>  
> And I have a platform with max_align = 32 and a platform with max_align 
> = 64.
> One platform will make FOOA be 24 bytes, the other 32.
>   One platform will pad out FOO to be align the 8 byte LONGFLOAT, one won't.
> Can that pickle be read/written by the two platforms?
> And how does the code know/detect the difference?
> That is, if a platform changed from max_align = 32 to 64, would the 
> pickle code work just
> as well on the "same" platform as on the "different" platforms?
>  

Yes, this will work fine.  The header of the pickle file has a compact
binary encoding of a copy of the RTPacking.T value for the target where
the pickle was written.  This contains target characteristics like max_align.

Reading a pickle compares the RTPacking.T value of the reading machine
with that in the pickle header and reconstructs the layout on both
machines, then does any necessary conversion.

>  
> I very recently changed NT386 max_align from 32 to 64, and I believe
> the remaining active platforms with max_align = 32 should also be 64.
> It would "only" affect pickles with LONGINT or LONGFLOAT, as well
> as "lining up" such structs with C.
>  
>  
> Such alignment shold make us not need the extra "unaligned double" switch
> on most platforms (some mystery still on some platforms) as well as
> perhaps be needed for some atomic operations, esp. maybe on
> LONGINT on 32bit x86.
>  
>  
>  - Jay
> 
>  
>  > From: dragisha at m3w.org
>  > To: rodney_bates at lcwb.coop
>  > Date: Sun, 31 Jan 2010 22:14:47 +0100
>  > CC: m3devel at elegosoft.com
>  > Subject: Re: [M3devel] platform-independent packing/alignment?
>  >
>  > I've not changed my code, that is for sure.... But now I am not sure
>  > some parent type (esp MUTEX here an there) was not changed... I'll take
>  > a look on this again sometime soon and report my findings.
>  >
>  > Thanks for clues.
>  >
>  > On Sun, 2010-01-31 at 14:00 -0600, Rodney M. Bates wrote:
>  > >
>  > > Dragiša Durić wrote:
>  > > > I've asked this before, but didn't catch answer:
>  > > >
>  > > > On Sun, 2010-01-31 at 12:21 +0000, Jay K wrote:
>  > > >> I suggest we can probably get by with platform-independent
>  > > >> packing/alignment settings.
>  > > >
>  > > > Some time ago I've used pickles (CM3) to save some data... My program
>  > > > does not read that pickle anymore....
>  > >
>  > > And you are certain your program that tries to read still contains
>  > > exact structurally equivalent types to all the types in the pickle?
>  > >
>  > > >
>  > > > Someone remembers moment when this incompatible changes were made?
>  > --
>  > Dragiša Durić <dragisha at m3w.org>
>  >



More information about the M3devel mailing list