Record size

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Record size

Carsten Bager
I have a data record ("sVar_typ") compiled with the 2.2.5 arm compiler. It has the size of
32728 byte.
Now I try to compile with the 2.4.5 arm compiler it has the size of 32736 byte.

I write the addresses of the variables in the record, they have not changed.
It looks like the compiler just adds 8 byte to the record at the end.
If I use "Packed" in the record, the 8 byte disappears.
Because the record is used in a file, I have to know the size.
Is this an indented behavior of the compiler?

Regards Carsten


  sVar_typ = Record                
    case Boolean of
      True:(                              
       version:integer32;                  
       PanelStart:Integer32;              
       ops:spOps_typ;                      
       aabLuk:aabLukTid_typ;              
       text:textS_typ;
       MontPgm:mont_Typ;                  
       mdI:mPgmDataFeltI_typ;              
       Pris:Pris_typ;                      
       hh:hh_typ;                          
       pris2tid:pris2tid_typ;              
       SommerTid:SommerTid_typ;            
       TurFdat:TurFdat_typ;                
       TurGdat:TurGdat_typ;                
       Modul:Modul_typ;                    
       MaskinText: array[0..30] of shortString;
       dorGruppe:  array[MinMas..MaxMas] of integer32;
       debug:Debug_typ);                    
     False:(data:packed array[0..8180] of integer32;
     ckSum:integer32);                      
  End;

  Writeln(hexstr(longword(@sVar),8));
  Writeln(hexstr(longword(@sVar.version),8));
  Writeln(hexstr(longword(@sVar.PanelStart),8));
  Writeln(hexstr(longword(@sVar.ops),8));
  Writeln(hexstr(longword(@sVar.aabLuk),8));
  Writeln(hexstr(longword(@sVar.text),8));
  Writeln(hexstr(longword(@sVar.MontPgm),8));
  Writeln(hexstr(longword(@sVar.mdI),8));
  Writeln(hexstr(longword(@sVar.Pris),8));
  Writeln(hexstr(longword(@sVar.hh),8));
  Writeln(hexstr(longword(@sVar.pris2tid),8));
  Writeln(hexstr(longword(@sVar.SommerTid),8));
  Writeln(hexstr(longword(@sVar.TurFdat),8));
  Writeln(hexstr(longword(@sVar.TurGdat),8));
  Writeln(hexstr(longword(@sVar.Modul),8));
  Writeln(hexstr(longword(@sVar.MaskinText),8));
  Writeln(hexstr(longword(@sVar.dorGruppe),8));
  Writeln(hexstr(longword(@sVar.debug),8));
  Writeln(hexstr(longword(@sVar.ckSum),8));
  Writeln(sizeof(sVar_typ));
 

Compiler 2.4.5
000F3694
000F3694
000F3698
000F369C
000F382C
000F38D4
000F57D4
000F5814
000F6014
000F6514
000F6524
000F6604
000F66A4
000F66F8
000F6978
000F69D4
000F88D4
000F8954
000FB668
32736


Compiler 2.2.5
000F3694
000F3694
000F3698
000F369C
000F382C
000F38D4
000F57D4
000F5814
000F6014
000F6514
000F6524
000F6604
000F66A4
000F66F8
000F6978
000F69B8
000F88B8
000F8938
000FB668
32728

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Record size

Jonas Maebe-2

On 24 May 2011, at 15:54, Carsten Bager wrote:

> I have a data record ("sVar_typ") compiled with the 2.2.5 arm  
> compiler. It has the size of
> 32728 byte.
> Now I try to compile with the 2.4.5 arm compiler it has the size of  
> 32736 byte.
>
> I write the addresses of the variables in the record, they have not  
> changed.
> It looks like the compiler just adds 8 byte to the record at the end.
> If I use "Packed" in the record, the 8 byte disappears.
> Because the record is used in a file, I have to know the size.
> Is this an indented behavior of the compiler?

The size of non-packed records can change at any time between compiler  
releases. If you need a known layout, you must use a packed record.

Padding at the end of a record is generally added to make sure that if  
such a record appears in an array, subsequent items all have the  
required alignment. I don't immediately see why the compiler would  
think that record needs alignment to a multiple of 16 bytes though  
(afaik, we don't support any datatypes on the ARM that require such an  
alignment).


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Record size

Jonas Maebe-2

On 24 May 2011, at 16:06, Jonas Maebe wrote:

> Padding at the end of a record is generally added to make sure that  
> if such a record appears in an array, subsequent items all have the  
> required alignment. I don't immediately see why the compiler would  
> think that record needs alignment to a multiple of 16 bytes though  
> (afaik, we don't support any datatypes on the ARM that require such  
> an alignment).

See also http://wiki.freepascal.org/User_Changes_2.4.0#Alignment_of_record_variables

And make sure to also read the User Changes pages for 2.4.2 and 2.4.4.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal