89

为什么鸟哥说 int 再怎么随机也申请不到奇数地址

 6 years ago
source link: https://mengkang.net/1046.html?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
鸟哥微博为什么要字节对齐需要字节对齐的根本原因在于CPU访问数据的效率问题。因为CPU每次都是从以4字节(32位CPU)或是8字节(64位CPU)的整数倍的内存地址中读进数据的。(更深入的原因,谁告知下),如果不对齐的话,很有可能一个4字节int需要分两次读取。具体演示看下面的实验。数据类型自身的对齐值按各数据类型自身大小进行对齐。变量的内存地址正好位于它长度的整数倍实验#include

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK