可以使用MemoryLayout获取数据类型占用的内存大小
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
enum Password {
case number(Int, Int, Int, Int) // 32
case other
}
var pwd = Password.number(5, 6, 4, 7) // 33
pwd = .other // 0
MemoryLayout<Password>.size // 33
MemoryLayout<Password>.stride // 40
MemoryLayout<Password>.alignment // 8
|