?
Solved

Holes in records

Posted on 2000-04-27
4
Medium Priority
?
356 Views
Last Modified: 2010-04-04
How can I avoid a hole in the memory when defining a record?
example:

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

here is the sizeOf(x) = 6
I want it to be 4, so no memory holes between the bytes and the word!
0
Comment
Question by:barzangy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 7

Expert Comment

by:Motaz
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

Motaz
0
 
LVL 1

Accepted Solution

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

ie:

var x : packed record

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

Tim.
0
 
LVL 10

Expert Comment

by:Lischke
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:

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

Ciao, Mike
0
 
LVL 3

Expert Comment

by:sburck
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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