Daily iOS
Memory and ARC

Memory layout

What are MemoryLayout<T>.size, stride, and alignment, and why can the three differ? Use the struct below as your example.

struct A { var a: Bool; var b: Int64; var c: Bool }
How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

size is the actual data bytes, alignment is the constraint on the start address, and stride is the distance to the next element in an array (size rounded up to alignment). They differ because of the padding between fields and at the end.

Share a question