美文网首页
Swift 5 MemoryLayout

Swift 5 MemoryLayout

作者: 鬼把戏 | 来源:发表于2019-10-08 10:02 被阅读0次

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)

相关文章

网友评论

      本文标题:Swift 5 MemoryLayout

      本文链接:https://www.haomeiwen.com/subject/luvqyctx.html