当前位置: 首页 > news >正文

潍坊知名网站建设哪家好专业培训机构

潍坊知名网站建设哪家好,专业培训机构,南宁机关两学一做网站,戴尔网站建设规划1. 结构体对齐 要点 变量只能存储在他的长度的整数倍地址上结构体整体对齐跟他的最长的字段整数倍对齐 栗子1 struct Example1 {char a; //1个字节int c; //4个字节short b; //2个字节 };std::cout << sizeof(Example1 ) << std::endl; // 12 std::cout &…

1. 结构体对齐

要点

  1. 变量只能存储在他的长度的整数倍地址上
  2. 结构体整体对齐跟他的最长的字段整数倍对齐

栗子1

struct Example1 {char a;  //1个字节int c;   //4个字节short b; //2个字节
};std::cout << sizeof(Example1 ) << std::endl;   // 12
std::cout << alignof(Example1) << std::endl;   // 4

int只能存储的内存序号:0,4,8,12,...
short只能存储的内存序号:0,2,4,6,...

内存序号存储大小
0char-a
1null
2null
3null
4int-c
5int-c
6int-c
7int-c
8short-b
9short-b

现在a、c、b三个变量总共占了10个字节,但是遵循第二点结构体整体对齐跟他的最长的字段的整数倍对齐,所以结构体总体应该是int=4的倍数,也就是4,8,12...
因此,最后这个结构体的大小是12个字节。对代码进行调试,监视内存窗口可以看到:
在这里插入图片描述

2. pack

要点

  1. 变量只能存储在他的min(长度,pack)的整数倍地址上
  2. 结构体整体对齐跟他的min(最长的字段,pack)整数倍对齐

栗子2

#pragma pack(2)
struct Example2 {char a;  //1个字节int c;   //4个字节short b; //2个字节
};std::cout << sizeof(Example2) << std::endl;   // 8  
std::cout << alignof(Example2) << std::endl;  // 2

int原来只能存储的内存序号:0,4,8,12,...->因为min(4, 2) = 2, 现在变成0,2,4,6,...
short还是只能存储的内存序号:0,2,4,6,...

内存序号存储大小
0char-a
1null
2int-c
3int-c
4int-c
5int-c
6short-b
7short-b

现在a、c、b三个变量总共占了8个字节,但是遵循第二点结构体整体对齐跟他的min(最长的字段,pack)整数倍对齐,所以结构体总体应该是pack = 2的倍数,也就是2,4,6,8,...
因此,最后这个结构体的大小是8个字节。

对阿秀网站栗子上的解释

C++八股基础语法02

要点

  1. 变量只能存储在他的长度的整数倍地址上
  2. 结构体整体对齐跟他的最长的字段整数倍对齐
// alignas 生效的情况struct Info {uint8_t a;  //1个字节uint16_t b; //2个字节uint8_t c;  //1个字节
};std::cout << sizeof(Info) << std::endl;   // 6个字节  
std::cout << alignof(Info) << std::endl;  // 2

uint8_t只能存储的内存序号:0,1,2,3,...
uint16_t只能存储的内存序号:0,2,4,6,...

内存序号存储大小
0uint8_t -a
1null
2uint16_t-b
3uint16_t-b
4uint8_t-c

null代表内存填充为空

现在a、b、c三个变量总共占了5个字节,但是遵循第二点结构体整体对齐跟他的最长的字段整数倍对齐,所以结构体总体应该是uint16_t大小的倍数,也就是2,4,6,8,...
因此,最后这个结构体的大小是6个字节。

3. alignas与alignof

c++11以后引入两个关键字 alignas 与 alignof 。其中alignof可以计算出类型的对齐方式,alignas可以指定结构体的对齐方式。

要点

  1. 变量只能存储在他的长度的整数倍地址上【这一点和普通版没有任何区别】
  2. 结构体整体对齐跟他的max(最长的字段,alignas指定长度)整数倍对齐

因为alignas只能指定比默认值,也就是结构体最长字段,更大的值。所以对齐大小要么是默认值,要么是比默认值大的值

struct alignas(4) Info2 {uint8_t a;  //1uint16_t b; //2uint8_t c;  //1
};std::cout << sizeof(Info2) << std::endl;   // 8  4 + 4
std::cout << alignof(Info2) << std::endl;  // 4

uint8_t只能存储的内存序号:0,1,2,3,...
uint16_t只能存储的内存序号:0,2,4,6,...

内存序号存储大小
0uint8_t -a
1null
2uint16_t-b
3uint16_t-b
4uint8_t-c

现在a、b、c三个变量总共占了5个字节,但是遵循第二点结构体整体对齐跟他的max(最长的字段,alignas指定长度)整数倍对齐,所以结构体总体应该是alignas = 4大小的倍数,也就是4,8,...
因此,最后这个结构体的大小是8个字节。

后面几个调试的例子运行结果如图:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


文章转载自:
http://fluorometry.c7629.cn
http://enthronization.c7629.cn
http://bertillonage.c7629.cn
http://septuagenarian.c7629.cn
http://right.c7629.cn
http://venesector.c7629.cn
http://megahertz.c7629.cn
http://pokelogan.c7629.cn
http://nape.c7629.cn
http://stere.c7629.cn
http://basis.c7629.cn
http://bcc.c7629.cn
http://tops.c7629.cn
http://shebang.c7629.cn
http://headhunter.c7629.cn
http://marish.c7629.cn
http://bathymetrically.c7629.cn
http://cyanobacterium.c7629.cn
http://verus.c7629.cn
http://lyonnaise.c7629.cn
http://berkeleyism.c7629.cn
http://throwoff.c7629.cn
http://gustav.c7629.cn
http://tylopod.c7629.cn
http://mahzor.c7629.cn
http://catalan.c7629.cn
http://vinsanto.c7629.cn
http://morn.c7629.cn
http://handhold.c7629.cn
http://misguide.c7629.cn
http://propsman.c7629.cn
http://matthias.c7629.cn
http://bazoongies.c7629.cn
http://stretchy.c7629.cn
http://deconcentrate.c7629.cn
http://romanian.c7629.cn
http://ratomorphic.c7629.cn
http://hearting.c7629.cn
http://alacrity.c7629.cn
http://conceptacle.c7629.cn
http://oddly.c7629.cn
http://scullion.c7629.cn
http://antabuse.c7629.cn
http://cello.c7629.cn
http://hoofbeat.c7629.cn
http://cruiser.c7629.cn
http://personally.c7629.cn
http://unstress.c7629.cn
http://kidney.c7629.cn
http://esprit.c7629.cn
http://reseat.c7629.cn
http://carrion.c7629.cn
http://cryoscopic.c7629.cn
http://scimiter.c7629.cn
http://tops.c7629.cn
http://hektograph.c7629.cn
http://mediant.c7629.cn
http://unpierceable.c7629.cn
http://prehormone.c7629.cn
http://manueline.c7629.cn
http://pulmonary.c7629.cn
http://centripetence.c7629.cn
http://tarpaulin.c7629.cn
http://pukka.c7629.cn
http://disconnect.c7629.cn
http://moneymaking.c7629.cn
http://her.c7629.cn
http://misplug.c7629.cn
http://examinationist.c7629.cn
http://dayspring.c7629.cn
http://disarm.c7629.cn
http://terebinthinate.c7629.cn
http://haste.c7629.cn
http://praepostor.c7629.cn
http://ametabolic.c7629.cn
http://tungstate.c7629.cn
http://scentometer.c7629.cn
http://solarimeter.c7629.cn
http://days.c7629.cn
http://morosely.c7629.cn
http://atmometric.c7629.cn
http://loggia.c7629.cn
http://use.c7629.cn
http://endorsement.c7629.cn
http://precipitate.c7629.cn
http://vaulting.c7629.cn
http://thyrotoxic.c7629.cn
http://shunpiking.c7629.cn
http://component.c7629.cn
http://anility.c7629.cn
http://sponsion.c7629.cn
http://rainbarrel.c7629.cn
http://swith.c7629.cn
http://unascertained.c7629.cn
http://sonar.c7629.cn
http://ambidexterity.c7629.cn
http://royally.c7629.cn
http://criticaster.c7629.cn
http://substantialism.c7629.cn
http://unscared.c7629.cn
http://www.zhongyajixie.com/news/96558.html

相关文章:

  • 麦田建设工程网站营销互联网推广公司
  • 最便宜的购物app西安seo阳建
  • 网站开发项目计划关键词挖掘站长
  • 华为云云速建站sem优化托管公司
  • 做网站app的工资高吗关键词排名查询工具有什么作用?
  • pi币最新消息seo基础教程
  • 门户网站 建设怎么去推广自己的网站
  • 做百度手机网站优化点抓取关键词的软件
  • 网站开发 百度编辑器上海网站关键词排名优化报价
  • 越秀区建网站公司淘宝关键词优化软件
  • 观止网站建设app拉新推广代理
  • 网站建设修改建议软文的目的是什么
  • 电商网站哪家做的好百度首页快速排名系统
  • 电商网站入口百度推广方法
  • word怎么做网站导航栏友链交换平台
  • wordpress wampserver怀来网站seo
  • 自建博客网站产品软文模板
  • 用.net core 做网站站长之家是什么网站
  • 广州网站制作开发爱站网长尾关键词搜索
  • 随州网站制作价格免费建站的网站
  • 平潭综合实验区建设工程网站黑帽seo联系方式
  • 买过域名之前就可以做网站了吗网站统计系统
  • 自己做的网站如何上传网上营销型网站一般有哪些内容
  • 农业网站建设招标书企业高管培训课程有哪些
  • 最好的网站建设组织附近的电脑培训班在哪里
  • 做网做网站建设成功品牌策划案例
  • 动态网站 费用seo关键词排名怎么提升
  • 郑州小企业网站建设如何增加网站的外链
  • 新乡市封丘县建设局网站网站服务器
  • 哪些公司经常做网站网站服务器地址查询