Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3631762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:26:20+00:00 2026-05-19T00:26:20+00:00

In C/C++ you always have SizeOf(array[N] of T) = N * SizeOf(T); In Pascal/Delphi

  • 0

In C/C++ you always have

SizeOf(array[N] of T) = N * SizeOf(T);

In Pascal/Delphi you can use ‘packed array’ to be sure that the above assert is true, but does ‘packed’ specifier have any practical value for arrays in Delphi? I can’t create an example of ‘unpacked’ array, the arrays seems always ‘packed’:

type
  A = array[0..2] of Byte;
  B = array[0..99] of A;
  C = packed record
    C1, C2, C3: Byte;
  end;
  D = array[0..99] of C;

procedure TForm10.Button1Click(Sender: TObject);
begin
  Assert(SizeOf(A) = 3);
  Assert(SizeOf(B) = 300);
  Assert(SizeOf(D) = 300);
end;

(The C/C++ structures and Delphi records are different – they can be ‘unpacked’ so that the size of the structure is greater than the sum of fields’ sizes due to the fields’ alignment.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:26:21+00:00Added an answer on May 19, 2026 at 12:26 am

    It has no practical effect in Delphi. The only type it could reasonably affect is the type with the oddest alignment and size combination, Extended, which has a size of 10 and an alignment of 8. However, arrays of Extended are essentially packed already (though they still have an alignment of 8; if the packed directive worked like it did on records, they would have an alignment of 1).

    Why do I say arrays of Extended is the only type it could affect? There is no other Delphi type, built-in or that you can compose, which has a size that is not an integer multiple of its alignment (leaving aside older versions of Delphi, and some bugs). Alignment is the thing that makes records larger with padding; it causes fields to be spaced out so that every field starts at an offset which is an integer multiple of its type’s alignment. In the analogous case with arrays, there is only one type involved, and if the size is already a multiple of the type’s alignment, then there’s no need for padding.

    Here’s a program which shows how Extended affects size and alignment depending on whether it’s wrapped in a record or not; you can add packed to the arrays, and see it makes no difference:

    type
      TWrap = record
        X: Extended;
      end; // field size=10, align=8, => actual size=16
    
      TArr1 = array[1..3] of TWrap; // 3*16 => size=48, align=8
      TArr2 = array[1..3] of Extended; // 3 * 10 => size=30, align=8
    
      TRec1 = record
        A: Byte;
        B: TArr1;
      end;
    
      TRec2 = record
        A: Byte;
        B: TArr2;
      end;
    
    var
      x: TRec1;
      y: TRec2;
    begin
      Writeln('Size of TArr1: ', SizeOf(TArr1));
      Writeln('Alignment of TArr1: ', Integer(@x.B) - Integer(@x.A));
      Writeln('Size of TArr2: ', SizeOf(TArr2));
      Writeln('Alignment of TArr2: ', Integer(@y.B) - Integer(@y.A));
    end.
    

    More words about alignment and packed: packed has another effect (on records) rather than just guaranteeing that there is no padding added: it also marks the record as having itself an alignment of 1. This has the negative effect of causing it to be frequently misaligned when it is used elsewhere. For purposes of language / OS interoperability, only in the case where the other language is not using OS alignment rules (normally meaning C alignment rules) should the packed directive be used. (Some Windows API headers have incorrect alignment for types defined within them, mind you, and have had to live with it ever since.) For purposes of compatibility with a file format, on the other hand, packed may be justified, but there are lots of other concerns there too, with respect to type choice (e.g. Integer was 2 bytes in 16-bit Delphi, but 4 bytes subsequently).

    Delphi tries to use C-compatible rules for alignment. In the past, it had some bugs here (particularly with records like TRec = record A, B: Extended end; versus TRec = record A: Extended; B: Extended end;), but these bugs should be fixed now

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've learned in College that you always have to free your unused Objects but
I always have found the open source space interesting but have never actually participated
I always have this notion that writing SQL queries in the code behind is
This seems like a pretty softball question, but I always have a hard time
I have always thought that the .equals() method in java should be overridden to
I have an array of a large structure that I am trying to output
I have always felt that in general the main work of a class should
I always have heard this motto from many entrepeneurs: do what you are passionate
I seem to always have problems with converting data to and from XML in
When I have one app.config in my main project I always have to duplicate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.