[fpc-pascal] Cache-line alignment for records
Matias Ezequiel Vara Larsen
matiasevara at gmail.com
Wed Mar 29 16:00:19 CEST 2023
On Wed, Mar 29, 2023 at 08:33:58AM +0200, Sven Barth via fpc-pascal wrote:
> Matias Ezequiel Vara Larsen via fpc-pascal <fpc-pascal at lists.freepascal.org>
> schrieb am Mi., 29. März 2023, 00:27:
>
> > Hello,
> >
> > On Mon, Mar 27, 2023 at 09:35:38PM +0200, Jonas Maebe via fpc-pascal wrote:
> > > On 27/03/2023 21:25, denisgolovan via fpc-pascal wrote:
> > >
> > > > But it's still not possible to attach alignment to type itself instead
> > of variable, right?
> > >
> > > It is possible (
> > https://gitlab.com/freepascal.org/fpc/source/-/blob/main/tests/test/talignrec1.pp
> > ),
> > > but it is subject to the same limitations when declaring variables of
> > those
> > > types.
> > >
> >
> > Thanks, this is what I was looking for, however, when the type is
> > defined as an array, only the [0] element is aligned. I was expecting
> > that each element in the array would be aligned.
> >
>
> No, array types are defined as never having padding between the elements.
> You need to make sure that the element is appropriately sized then.
>
So if I have a type like:
test = record
r: DWord;
s: Word;
end;
Then, I define the variable `nada` as an array of `test` type:
var
nada: array[0..2] of test;
Is the `@nada[1].r` element aligned to 4-bytes?
Thanks, Matias.
More information about the fpc-pascal
mailing list