Records are aligned unless you specify the "packed" attribute (ie
TSample = packed record). The size returned by SizeOf *is* the real size
for the record, that's the number of bytes used to hold the structure in
memory.

Remember, you're not supposed to use non-packed records for anything
outside your version of the Exe (no file-saving, no network
transmission), and that's because alignment might be different for
different compilers (or different versions of the same compiler).

--
Cosmin Prund 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of CubicDesign
Sent: Wednesday, May 16, 2007 6:20 PM
To: [email protected]
Subject: problems with SizeOf

Hi.
Can anybody tell me what should return this function Sizeof(TSample)?

 TSample = record                        
    SampleA: 
Smallint;                                                         
    SampleB: 
Smallint;                                                         
    SampleC: Smallint;
    SampleD: Smallint;
    BasePos: Integer;                    
    Base  : 
char;                                                           
    QV     : BYTE;
    Gray   : Boolean;
  end;              {Size= 2+2+2+2+ 4+ 1+ 1+ 1}

Why it returns 16 instead of 15?
It is because the data is aligned to word or double-word boundaries for 
faster access?
How do I get the real size then?




I want to save a matrix called CromaMX (CromaMX = array of TSample ) to 
disk using BlockWrite. How do I save it, without wasting disk space, 
because it looks that if I use:

  SizeChroma= Length(CromaMX)* sizeof(TSample);
  BlockWrite(F, CromaMX[0],  SizeChroma);          

I will allocate too much space.




_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to