Holes in records

Posted on 2000-04-27
Last Modified: 2010-04-04
How can I avoid a hole in the memory when defining a record?

var x: record
a: byte;
b: word;
c: byte;

here is the sizeOf(x) = 6
I want it to be 4, so no memory holes between the bytes and the word!
Question by:barzangy

Expert Comment

ID: 2754826
By default there is no holes between record fields, even if you define an array of records there is no holes btween each record and the another one


Accepted Solution

AttarSoftware earned 50 total points
ID: 2754830
Does the packed keyword do this?


var x : packed record

I might not have the syntax right, but the help files should help with this...

LVL 10

Expert Comment

ID: 2754843
Tim is right. The "holes" are there to align members of the record at a particular boundary to inrease access speed. In order to avoid record alignment use:

  x: packed record
    a: byte;
    b: word;
    c: byte;

Ciao, Mike

Expert Comment

ID: 2754866
Beyond declaring a record as packed, you have a compiler option for record field alignment $A+/-.  This is from the help file:

The $A directive controls alignment of fields in record types.
In the {$A+} state, fields in record types that are declared without the packed modifier are aligned. In the {$A-} state, fields in record types are never aligned. Record type field alignment is described in the Object Pascal Language Guide.
Regardless of the state of the $A directive, variables and typed constants are always aligned for optimal access. In the {$A+} state, execution will be faster.

In your case, however, use packed, which will override this.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now