Solved

Holes in records

Posted on 2000-04-27
4
352 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 50 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 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