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.

MrNickBarker commented Mar 16, 2018

Will the compiler ever optimize CertifiedPuppy2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment