Solved

Holes in records

Posted on 2000-04-27
4
346 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
4 Comments
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 226
APK file name 7 63
Save pdf file to other location 3 72
Convert Jpg /PNG To GIF 5 101
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

13 Experts available now in Live!

Get 1:1 Help Now