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