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
Solved

Holes in records

Posted on 2000-04-27
4
351 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

856 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