struct对象在内存中所占的空间大小(内存对齐)
摘要:
对于一个struct对象,其在内存中所占空间的大小往往不是所有成员的字节大小相加之和。运行下面代码看一下:#include<iostream> usingnamespacestd;//union structdemo{charc;shorts;inti;longl;floatf;doubled;longdoublelb;};intmain(){cout<<sizeof(demo)<<endl;return0;} 我在WindowsXp,vs2008下输出为32,为什么不是1+2+4+4+4+8+8呢?因为struct对象在存储时采用对齐原则,Windows默 阅读全文
posted @ 2008-11-27 22:11 NULL00 阅读(1141) 评论(0) 推荐(0) 编辑