News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Structure alignment

Started by sinsi, December 31, 2017, 10:30:59 AM

Previous topic - Next topic

sinsi

Within a structure, items should be naturally aligned

structure1 struct
  v32_1    dd ? ;offset 0
           dd ? ;offset 4, padding
  v64_1    dq ? ;offset 8
structure1 ends


Automatically aligned?

structure1 struct 8
  v32_1    dd ? ;offset 0
  v64_1    dq ? ;offset 8
structure1 ends


Should a structure pad the end to align 8?

structure2 struct 8
  v64_1    dq ? ;offset 0
  v32_1    dd ? ;offset 8
           dd ?
structure2 ends


Does alignment only matter within a structure?

var1  dd ?          ;.data? offset 0
str2  structure2 <> ;.data? offset 4 - str2.v64_1 not aligned to 8 - doesn't matter?

Tá fuinneoga a haon déag níos fearr :biggrin:

nidud

#1
deleted

sinsi

So memory alignment isn't required but would be more efficient.
Does the -Zp[n] switch override the structure definition?

Would a nested structure need alignment within the main structure?


Thanks for your time.
Tá fuinneoga a haon déag níos fearr :biggrin:

jj2007

I agree with Nidud that the Zp switch is the way to go. -Zp8 for 64-bit code, to be precise. Everything else is a can of worms.