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)

结果:
image

enum Password{
    case num(Int, Int, Int, Int)
    case other
}

MemoryLayout<Password>.size
MemoryLayout<Password>.stride
MemoryLayout<Password>.alignment

结果:

image

posted @   基地您  阅读(287)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示