Swift 5 MemoryLayout

MemoryLayout

  • 获取数据类型占用内存的大小
var age = 10


MemoryLayout.size //实际占用的内存大小
MemoryLayout.stride //分配的内存大小
MemoryLayout.alignment //内存对齐参数

MemoryLayout.size(ofValue: age)
MemoryLayout.stride(ofValue: age)
MemoryLayout.alignment(ofValue: age)

enum Season {
    case spring, summer
}

var s = Season.spring
MemoryLayout.size(ofValue: s)
MemoryLayout.stride(ofValue: s)
MemoryLayout.alignment(ofValue: s)

你可能感兴趣的:(Swift 5 MemoryLayout)