Is there extra space for options for entries?

I am working with recording the options below. The variable instance is Kro_Combi. SizeOf (Kro_Combi) reports 7812 bytes. SizeOf (Kro_Combi.data) reports 7810 bytes. The SizeOf sum of all the other data structures that make up the "indirect" write case also adds 7810 bytes.

Why is there a two byte difference? I would like both options to overlap.

TKro_Combi = record
  case directmode:boolean of
    true : (
      data : array[0..7809] of byte
           );
    false : (
      Combi_Name            : array[0..23] of char;                //24
      Gap1                  : array[0..63] of byte;                // 24-87 (64)
      Ins_Effect_Group      : array[1..12] of TIns_Effect_Params;  //74 each,   (Ins_Effect_Data=9 bytes)  74*12 = 888
      Mast_Effect_Params    : array[0..229] of byte;               // 976-1205 : 230 bytes
      Vect_Aud__Drum_Params : array[0..97] of byte;                //1206-1303  : 98 bytes
      Karma_Common          : array[0..509] of byte;               //1304-1813 : 510 bytes
      Karma_Module          : array[0..3] of TKarma_Module;        //1814-2557 : 744 bytes each  Total span 1814 - 4789 = 2976 bytes total
      Common_Params         : array[0..11] of byte;                //4790-4801 = 12 bytes
      Timbre_Group          : array[1..16] of TTimbre_Params;   )  // 4802 -4989 = 188 bytes each,  16 Timbres, 4802-7809 = 3008 bytes total for all
  end;

      

+3


source to share


1 answer


First of all, there must be room for the field directmode

. If you really want the record to be 7810 bytes, you must remove this field. Another byte will be associated with the internal alignment and padding of false

the write variant portion . I still can't figure out where he comes from. Regardless, you just want to use packed write to avoid padding bytes.



TKro_Combi = packed record  
case boolean of
true : (
  data : array[0..7809] of byte
       );
false : (
  Combi_Name            : array[0..23] of char;                //24
  Gap1                  : array[0..63] of byte;                // 24-87 (64)
  Ins_Effect_Group      : array[1..12] of TIns_Effect_Params;  //74 each,   (Ins_Effect_Data=9 bytes)  74*12 = 888
  Mast_Effect_Params    : array[0..229] of byte;               // 976-1205 : 230 bytes
  Vect_Aud__Drum_Params : array[0..97] of byte;                //1206-1303  : 98 bytes
  Karma_Common          : array[0..509] of byte;               //1304-1813 : 510 bytes
  Karma_Module          : array[0..3] of TKarma_Module;        //1814-2557 : 744 bytes each  Total span 1814 - 4789 = 2976 bytes total
  Common_Params         : array[0..11] of byte;                //4790-4801 = 12 bytes
  Timbre_Group          : array[1..16] of TTimbre_Params;   )  // 4802 -4989 = 188 bytes each,  16 Timbres, 4802-7809 = 3008 bytes total for all
end;

      

+7


source







All Articles