swift计算使用内存大小,MemoryLayout使用
MemoryLayout使用
var age = 18
MemoryLayout<Int>.size // 实际用到的大小
MemoryLayout<Int>.stride //分配的内存大小
MemoryLayout<Int>.alignment //对齐参数
MemoryLayout.size(ofValue: age)
MemoryLayout.stride(ofValue: age)
MemoryLayout.alignment(ofValue: age)
结果:
enum Password{
case num(Int, Int, Int, Int)
case other
}
MemoryLayout<Password>.size
MemoryLayout<Password>.stride
MemoryLayout<Password>.alignment
结果: