CubicDesign wrote:
> 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?
Yes.
> How do I get the real size then?
SizeOf *is* the real size.
> 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.
Never, ever, write a record to disk if it isn't declared as "packed."
Look up the "packed" reserved word in the help for more details.
Also, never ever write a record to disk when it's declared using types
with sizes that change. The Integer and Char types are not guaranteed to
be four and one bytes, respectively. If your data format requires a
four-byte unsigned integer, then use LongInt. If you require a one-byte
character, use AnsiChar. The size of Char has already changed -- in
.Net, it's a two-byte type. The size of Integer is due to change for a
64-bit compiler. If you take you code to a new compiler, you don't want
the new version of your program to suddenly have a different idea of
what your data format is. Define it with types that won't change.
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi