MemoryLayout
- 获取数据类型占用内存的大小
var age = 10
MemoryLayout<Int>.size //实际占用的内存大小
MemoryLayout<Int>.stride //分配的内存大小
MemoryLayout<Int>.alignment //内存对齐参数
MemoryLayout<Int>.size(ofValue: age)
MemoryLayout<Int>.stride(ofValue: age)
MemoryLayout<Int>.alignment(ofValue: age)
enum Season {
case spring, summer
}
var s = Season.spring
MemoryLayout<Season>.size(ofValue: s)
MemoryLayout<Season>.stride(ofValue: s)
MemoryLayout<Season>.alignment(ofValue: s)