结构体内存对齐规则
来源:互联网 发布:淘宝ar扫描怎么用 编辑:程序博客网 时间:2024/04/29 07:16
1—————————————–
struct{ char b; int a; short c;}A;sizeof(A) = 12;b: 1*0 = 0a: 4*1 = 4c: 2*4 = 8 2-----
struct A{ int a; double b; float c;};struct{ char e[2]; int f; double g; short h; struct A i;}B;//对齐单位 8 个字节sizeof(B) = 48;//普通成员偏移量e: 2*0 = 0f: 4*1 = 4g: 8*1 = 8h: 2*8 = 16结构体起点坐标: 8*3 = 24//结构体成员偏移量a: 24 + 4*0 = 24b: 24 + 8*1 = 32c: 24 + 4*4 = 403------------------------
struct A{ char e; short f;};struct{ int a; char b; struct A c; char d;}B;sizeof(B) = 12;a: 4*0 = 0;b: 1*4 = 4;结构体起点坐标: 2*3 = 6e: 6+1*0 = 6f: 6+2*1 = 8d: 1*10 = 10
4-----------------struct A{ int e; short f;};struct{ int a; char b; struct A c; short d;}B;sizeof(B) = 20;a: 4*0 = 0b: 1*4 = 4结构体起点: 4*2 = 8e: 8 + 4*0 = 8f: 8 + 2*2 = 12 //结构体A所占的大小为该结构体成员内部最大元素的整数倍,不足补齐。d: 2*8 = 165-----------------
#pragma pack(2) //指定对齐单位为2个字节typedef struct{ int a; char b; short c; char d;}A;
a:2*0 = 0
b: 1*4 = 4
c: 2*3 = 6
d: 1*8 = 8
sizeof(A) = 10;
6——————
#pragma pack(2)typedef struct{ char a; char b; short c; int d;}A;a: 1*0 = 0b: 1*1 = 1c: 2*1 = 2d: 2*2 = 4sizeof(A) = 8;
1 0
- 结构体内存对齐规则
- 结构体内存对齐规则
- 结构体内存对齐规则
- 结构体内存对齐规则
- 结构体内存对齐规则
- 结构体内存对齐的规则
- 结构体内存对齐原因及规则
- 结构体内存对齐规则是什么?
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- 结构体内存对齐
- node平台express框架源码分析-3
- nyoj 题目128 前缀式计算
- android 项目进行混淆时,签名打包生产proguard文件是报错处理方法。
- LoadRunner脚本编写之一
- 多校联合训练10&&HDU 5861 Road
- 结构体内存对齐规则
- 暑期dp46道(46)--HDOJ 1069
- 62. Unique Paths(dp+深搜)
- POJ (简单 dp ,最长升序子串)
- mac电脑开发android找不到设备
- 文章标题
- 事件对象中target对象和currentTarget对象的区别
- Android混淆打包出错,出现类似 there were 100 duplicate class defin
- zzuli 1895: 985的0-1串难题(二分)