请问个有关问题
请教个问题
#include<iostream.h>
struct data
{
int a;
double b;
};
void main()
{
cout<<sizeof(data)<<endl;
}
结果为什么是16呢
------解决方案--------------------
看我博客的那篇文章 自然对齐的问题···
------解决方案--------------------
内存对齐了,被和谐了、、、百度“sizeof结构体”
------解决方案--------------------
涉及到 内存对齐的知识 lz 看看博文学习学习吧http://blog.sina.com.cn/s/blog_66e8549c01010qxn.html
加油!青年。。
------解决方案--------------------
内存对齐 以最大的为基准
------解决方案--------------------
这涉及字节对齐问题。这样做的目的是为了能更快地读取数据。具体的请看http://baike.baidu.com/view/1078660.htm
------解决方案--------------------
#include<iostream.h>
struct data
{
int a;
double b;
};
void main()
{
cout<<sizeof(data)<<endl;
}
结果为什么是16呢
------解决方案--------------------
看我博客的那篇文章 自然对齐的问题···
------解决方案--------------------
内存对齐了,被和谐了、、、百度“sizeof结构体”
------解决方案--------------------
涉及到 内存对齐的知识 lz 看看博文学习学习吧http://blog.sina.com.cn/s/blog_66e8549c01010qxn.html
加油!青年。。
------解决方案--------------------
内存对齐 以最大的为基准
------解决方案--------------------
这涉及字节对齐问题。这样做的目的是为了能更快地读取数据。具体的请看http://baike.baidu.com/view/1078660.htm
------解决方案--------------------
- C/C++ code
#include <iostream> using namespace std; struct data { int a; double b; }; int main() { cout<<"the size of int:"<<sizeof(int)<<endl; cout<<"the size of double:"<<sizeof(double)<<endl; cout<<"the size of struct data:"<<sizeof(data)<<endl; return 0; } /* 输出结果为: the size of int:4 the size of double:8 the size of struct data:16 原因分析: C/C++里面有一种机制叫做内存字节对齐,用于结构体中,为了提高读写效率才使用该机制,具体你可以百度一下“内存字节对齐” */