Originally Posted by
laggyluk
Should I use packed records for this purpose? the interweb says it has slower access performance than 'unpacked'
Example you quoted says packed, but it is actually byte-aligned to 32 and 64 bit, so it wouldn't make any difference.
Code:
TRGB1 = packed record
r, g, b: byte;
end;
This is not aligned. But if you make it an array and compare size:
Code:
TRGB2 = record
r, g, b: byte;
end;
arr1: array[0..255] of TRGB1;
arr2: array[0..255] of TRGB2;
The arr1 is 256-1280 bytes smaller than arr2. This is because if you take sizeof(TRGB1) you would get 3, but sizeof(TRGB2) would give you 4 or 8 depending on if you compile with 32 or 64 bit compiler, i guess... Now if you're dealing with OpenGL functions, you need to tell it exactly the structure of the data you are using. For that there is usually a "stride"-parameter, to describe the spacing. If you would send it color data, you should use TRGB1 style with size 3 bytes. All the data is in tight sequence without spaces in between. But actually you will notice that most records will be byte aligned anyway.
For example shader vertex-data, that will propably be the most time-critical array of them all, is byte-aligned no matter how you twist it:
Code:
TModelVertex = packed record
v, n: TVector; // 12+12 bytes
uv: TVector2f; // 8 bytes
end; // = 24+8 = 32 => 32/8 = 4 => aligned to 64 bits
Bookmarks