>var
> CromaMX       = packed array of TSample;
> CromaMXFast =            array of TSample;
>begin
>LoadFromDisk(CromaMX);
> CromaMXFast:= CromaMX;        <-- won't work
>end;>>
>Second problem:
>I suppose that if CromaMX is a packed array of TSample, then TSample 
>should be also packed. Right?

The point is to PACK the record, not the array, and NOT to create two
different types.
Adding packed to the array makes no difference (in this case, at least with
D2007) to
the SizeOf for an element or for the whole array, whether or not TSample is
packed.
You need to add packed to the record to make a difference.

For a single record, the Packed/unpacked issue would really not make any
measurable
performance difference (given that one of your 3 bytes has to be on the
"wrong" alignment anyway).
The problem in your case is that the second array element (e.g.) will start
misaligned and hence
so most of the structure will be misaligned for every access.

Personally, I would declare it packed, use the types that are defined not to
change
(as mentioned in another post), and then add 1 byte "reserved" to make sure
the structure
remained a nice round 16 bytes long to preserve alignment, and accept that
this means that
it will use 1/15 more disk space than necessary.

Alternatively I'd look at whether I really need to store the Boolean
separately, or could I
pack it as 1 bit into one of the other fields.
I did exactly that for data I was preparing for an embedded airborne system
where I needed a
single bit flag - the max value I was storing in one of the WORD fields
could never use 16 bits,
so I "stole" the top bit to be the Boolean and accepted that I had to mask
it in and out.
The small penalty on accessing this flag was acceptable in relation to the
effect on storage
requirements.

Ken

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

Reply via email to