Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all I think you need to be careful how you read the documentation. It has not been updated consistently and the fact that some parts appear specific to Win32 can in no way be used to infer that Win64 differs. In fact, for the issues raised in your question, there are no substantive differences between 32 and 64 bit.</p> <p>For Delphi, using packed on an array does not change the padding between successive elements. The distance between two adjacent elements of an array is equal to SizeOf(T) where T is the element type. This holds true irrespective of the use of the packed modifier. And using packed on an array does not even affect the alignment of the array. </p> <p>So, to be completely clear and explicit, <code>packed</code> has no impact at all when used on arrays. The compiler treats a packed array in exactly the same way as it treats a non-packed array.</p> <p>This statement seems to be at odds with the documentation. The <a href="http://docwiki.embarcadero.com/RADStudio/en/Structured_Types#Alignment_of_Structured_Types" rel="nofollow noreferrer">documentation</a> states:</p> <blockquote> <p><strong>Alignment of Structured Types</strong></p> <p>By default, the values in a structured type are aligned on word- or double-word boundaries for faster access.</p> <p>You can, however, specify byte alignment by including the reserved word packed when you declare a structured type. The packed word specifies compressed data storage. Here is an example declaration:</p> <pre><code>type TNumbers = packed array [1..100] of Real; </code></pre> </blockquote> <p>But consider this program:</p> <pre><code>{$APPTYPE CONSOLE} type TNumbers = packed array [1..100] of Real; type TRec = record a: Byte; b: TNumbers; end; begin Writeln(Integer(@TRec(nil^).a)); Writeln(Integer(@TRec(nil^).b)); Readln; end. </code></pre> <p>The output of which, using Delphi XE2, is:</p> <pre> 0 8 </pre> <p>So, using <code>packed</code> with arrays, in contradiction of the documentation, does not modify alignment of the type.</p> <p>Note that the above program, when compiled by Delphi 6, has output</p> <pre> 0 1 </pre> <p>So it would appear that the compiler has changed, but the documentation has not caught up.</p> <p>A related question can be found here: <a href="https://stackoverflow.com/questions/4583985/are-there-any-difference-between-array-and-packed-array-in-delphi">Are there any difference between array and packed array in Delphi?</a> But note that the answer of Barry Kelly (an Embarcadero compiler engineer at the time he wrote the answer) does not mention the change in compiler behaviour.</p> <hr> <blockquote> <p>Generally speaking, it would seem to me runtime code would be faster if never using padding between items.</p> </blockquote> <p>As discussed above, for arrays there never is padding between array elements.</p> <blockquote> <p>I believe default alignment in Delphi/64bit is 8 byte.</p> </blockquote> <p>The alignment is determined by the data type and is not related to the target architecture. So a Boolean has alignment of 1. A Word has alignment of 2. An Integer has alignment of 4. A Double has alignment of 8. These alignment values are the same on 32 and 64 bit.</p> <p>Alignment has an enormous impact on performance. If you care about performance you should, as a general rule, never pack data structures. If you wish to minimise the size of a structure (class or record), put the larger elements first to minimise padding. This could improve performance, but it could also worsen it.</p> <p>But there is no single hard and fast rule. I can imagine that packing could improve performance if the thing that was packed was hardly ever accessed. And I can, more readily in fact, imagine that changing the order of elements in a structure to group related elements could improve performance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload