Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Size, stride, and alignment of two structs
struct CertifiedPuppy1 {
let age: Int
let isTrained: Bool
let isCertified: Bool
}
MemoryLayout<CertifiedPuppy1>.size // 10
MemoryLayout<CertifiedPuppy1>.stride // 16
MemoryLayout<CertifiedPuppy1>.alignment // 8
struct CertifiedPuppy2 {
let isTrained: Bool
let age: Int
let isCertified: Bool
}
MemoryLayout<CertifiedPuppy2>.size // 17
MemoryLayout<CertifiedPuppy2>.stride // 24
MemoryLayout<CertifiedPuppy2>.alignment // 8
@MrNickBarker

This comment has been minimized.

Copy link

commented Mar 16, 2018

Will the compiler ever optimize CertifiedPuppy2?

@mrcompoteee

This comment has been minimized.

Copy link

commented Feb 25, 2019

Will the CertifiedPuppy2 be optimized?

@dehesa

This comment has been minimized.

Copy link

commented Sep 6, 2019

@MrNickBarker and @mrcompoteee As far as I understand the compiler won't optimize it.
The ABI contract states that structure order will be kept as it is written in code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.