相关疑难解决方法(0)

为什么某些类型(例如Float80)的内存对齐大于字大小?

为了使它具体,我只想知道为什么在我的64位mac上,Swift编译器说某些类型的对齐方式Float80是16. 要检查类型的内存对齐要求,我使用该alignof函数.

sizeof(Float80) // ~> 16 bytes, it only needs 10 bytes, but because of hardware design decisions it has to be a power of 2
strideof(Float80) // ~> 16 bytes, clear because it is exact on a power of 2, struct types with Float80 in it, can be bigger
alignof(Float80) // ~> 16 bytes, why not 8 bytes, like String ?
Run Code Online (Sandbox Code Playgroud)

我理解类型的内存对齐小于或等于单词的大小是有益的.

sizeof(String) // ~> 24 bytes, clear because 24 is multiple of …
Run Code Online (Sandbox Code Playgroud)

memory-alignment swift

6
推荐指数
2
解决办法
1384
查看次数

标签 统计

memory-alignment ×1

swift ×1