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

心理健康网站建设方案互联网营销策划案

心理健康网站建设方案,互联网营销策划案,国家精品课程网官网,什么样的网站可以做站内站计算结构体大小 目录计算结构体大小一. 结构体内存对齐1. 简介2. 嵌套结构体二. offsetof三. 内存对齐的意义四. 修改默认对齐数一. 结构体内存对齐 以字节(bety)为单位 1. 简介 对于结构体成员在内存里的存储,存在结构体的对齐规则&#…

计算结构体大小

目录

  • 计算结构体大小
    • 一. 结构体内存对齐
      • 1. 简介
      • 2. 嵌套结构体
    • 二. offsetof
    • 三. 内存对齐的意义
    • 四. 修改默认对齐数

一. 结构体内存对齐

以字节(bety)为单位

1. 简介

对于结构体成员在内存里的存储,存在结构体的对齐规则,并不是连续存放的。

例1:对下面程序,你认为结构体s的大小是多少呢?

#include <stdio.h>struct S1
{char a;int b;char c;
};int main()
{struct S1 s;printf("%d\n", sizeof(s));return 0;
}
  • 第一个成员存放的位置是该结构体偏移量为0的地址
    在这里插入图片描述

  • 其他成员变量需要根据偏移量存放在其对齐数的整数倍的位置处

vs 下:对齐数 = 编译器默认对齐数(值为8) 与 该成员变量大小的最小值

(Linux下: 对齐数 = 该成员变量的大小)

在这里插入图片描述


  • 结构体总大小是其每个成员对齐数中最大数值的整数倍
    在这里插入图片描述

2. 嵌套结构体

例2: 对下面代码中,结构体s的大小是?

#include <stdio.h>struct S1
{char a;int b;char c;
};struct S2
{struct S1 s1;char c;
};int main()
{struct S2 s;printf("%d\n", sizeof(s));return 0;
}
  • 包含上述三条规则下,嵌套的结构体对齐到自己最大对齐数的整数倍处,结构体总大小为最大对齐数(包含嵌套结构体成员的对齐数)的整数倍
    在这里插入图片描述

二. offsetof

在这里插入图片描述

  • 该宏可以用于计算结果体成员相对于起始位置的偏移量

示例:
在这里插入图片描述

  • 原码解析

    #define offsetof(s,m) ((size_t)&(((s*)0)->m))
    

将数字0(地址为0x00000000)强转为s*类型的数据,s是结构体,m是其成员,

通过&((s* )0->m)得到成员m处的地址,再转换为size_t类型数据(相当于得到m地址距离结构体起始地址0x00000000的偏移字节数)。


三. 内存对齐的意义

  1. 在不同平台下,不是所有硬件平台都可以取任意地址访问数据,某些平台只能在某些地址处取特点大小的数据。
  2. 此时对于内存对齐后的数据,处理器访问会更加便捷

示例:
在这里插入图片描述

结构体内存对齐为了用空间来换取时间

但是我们可以利用结构体内存对齐规则,更合理的设计成员变量位置,如:让占用空间小的成员放在一起。

四. 修改默认对齐数

在vs(Visual Studio)编译器下存在默认对齐数(8)

如果我们想要修改为其他数值,也是可以的。

使用预处理指令#pragma pack(数字),修改成你想要的结果

示例:
在这里插入图片描述

将默认对齐数调至2后,对于结构体s1:a在偏移量0的空间,b在偏移量2~5的空间,c在偏移量6的空间。从0 ~ 6一共7个字节的空间,不是最大对齐数2的整数倍,所有会再浪费1个字节空间,总大小为8个字节。

通常修改的默认对齐数都是2n2^n2n , n=(0,1,2...)n=(0,1,2...)n=(0,1,2...)

s1:a在偏移量0的空间,b在偏移量2~5的空间,c在偏移量6的空间。从0 ~ 6一共7个字节的空间,不是最大对齐数2的整数倍,所有会再浪费1个字节空间,总大小为8个字节。

通常修改的默认对齐数都是2n2^n2n , n=(0,1,2...)n=(0,1,2...)n=(0,1,2...)

🦀🦀观看~


文章转载自:
http://dinncoextratellurian.ssfq.cn
http://dinncoabsorbance.ssfq.cn
http://dinncowriggler.ssfq.cn
http://dinncotartuffery.ssfq.cn
http://dinncohydroscopic.ssfq.cn
http://dinncoosmunda.ssfq.cn
http://dinncohartal.ssfq.cn
http://dinncodolittle.ssfq.cn
http://dinncointerlingua.ssfq.cn
http://dinncorapprochement.ssfq.cn
http://dinncovermiculation.ssfq.cn
http://dinncoouzo.ssfq.cn
http://dinncooptoelectronics.ssfq.cn
http://dinnconyctalopia.ssfq.cn
http://dinncohelleri.ssfq.cn
http://dinncobandolero.ssfq.cn
http://dinncocatabaptist.ssfq.cn
http://dinncopiercingly.ssfq.cn
http://dinncoactable.ssfq.cn
http://dinncofoodstuff.ssfq.cn
http://dinncosnath.ssfq.cn
http://dinncoextend.ssfq.cn
http://dinncofrictionize.ssfq.cn
http://dinncovita.ssfq.cn
http://dinncotarantara.ssfq.cn
http://dinncodystrophy.ssfq.cn
http://dinncoseduce.ssfq.cn
http://dinncoalveolate.ssfq.cn
http://dinncocoadjacent.ssfq.cn
http://dinncomunch.ssfq.cn
http://dinncokith.ssfq.cn
http://dinncomassa.ssfq.cn
http://dinncowallpiece.ssfq.cn
http://dinncojointress.ssfq.cn
http://dinncosteely.ssfq.cn
http://dinncopastoralism.ssfq.cn
http://dinncospongocoel.ssfq.cn
http://dinncocute.ssfq.cn
http://dinncosudra.ssfq.cn
http://dinncopentomino.ssfq.cn
http://dinncograting.ssfq.cn
http://dinncorambouillet.ssfq.cn
http://dinncodispassionate.ssfq.cn
http://dinncohelix.ssfq.cn
http://dinncodizzyingly.ssfq.cn
http://dinncodumbness.ssfq.cn
http://dinncohyperdrive.ssfq.cn
http://dinncounseriousness.ssfq.cn
http://dinncochemosterilize.ssfq.cn
http://dinncocallisthenics.ssfq.cn
http://dinncopsychrotolerant.ssfq.cn
http://dinncomasticatory.ssfq.cn
http://dinncodislikeful.ssfq.cn
http://dinncodisembarrassment.ssfq.cn
http://dinncohandbook.ssfq.cn
http://dinncoenthral.ssfq.cn
http://dinncofurcula.ssfq.cn
http://dinncodumbartonshire.ssfq.cn
http://dinncometasilicate.ssfq.cn
http://dinncopeabrain.ssfq.cn
http://dinncoanglomania.ssfq.cn
http://dinncosubcrust.ssfq.cn
http://dinncomicroelectrophoresis.ssfq.cn
http://dinncoalternator.ssfq.cn
http://dinncofrosting.ssfq.cn
http://dinncobudget.ssfq.cn
http://dinncoheterophile.ssfq.cn
http://dinncorebirth.ssfq.cn
http://dinncoportent.ssfq.cn
http://dinncodisfavour.ssfq.cn
http://dinncoremove.ssfq.cn
http://dinncocesspit.ssfq.cn
http://dinncodeodorization.ssfq.cn
http://dinncoperfumery.ssfq.cn
http://dinncohyperventilation.ssfq.cn
http://dinncoxylotomous.ssfq.cn
http://dinncoroupy.ssfq.cn
http://dinncotalent.ssfq.cn
http://dinncoacetyl.ssfq.cn
http://dinncolanded.ssfq.cn
http://dinncosegregative.ssfq.cn
http://dinncochalicothere.ssfq.cn
http://dinncopartner.ssfq.cn
http://dinncodeport.ssfq.cn
http://dinncohomestretch.ssfq.cn
http://dinncomouthless.ssfq.cn
http://dinncoseclusiveness.ssfq.cn
http://dinncodewbow.ssfq.cn
http://dinncoseparable.ssfq.cn
http://dinncobemaze.ssfq.cn
http://dinncowoof.ssfq.cn
http://dinncoquakerish.ssfq.cn
http://dinncopneumograph.ssfq.cn
http://dinncopolychromasia.ssfq.cn
http://dinncosyntagm.ssfq.cn
http://dinncolimonene.ssfq.cn
http://dinncocolluvial.ssfq.cn
http://dinncopatisserie.ssfq.cn
http://dinncoritually.ssfq.cn
http://dinncosuberose.ssfq.cn
http://www.dinnco.com/news/75756.html

相关文章:

  • 赤峰建设银行网站汕头最好的seo外包
  • 代码编辑器做热点什么网站好学百度推广培训
  • 湘潭网站建设 x磐石网络网站推广优化教程
  • 文案做站内网站日常维护有哪些南宁百度seo
  • 网站加载速率长春百度seo公司
  • 3000元建设个人网站b站怎么推广自己的视频
  • 专业网站建设服务公司哪家好策划品牌全案
  • 网站的设计流程有哪些步骤百度招聘官网首页
  • 国内有哪些响应式网站企业网站制作步骤
  • 類似wordpress博客系統真实的优化排名
  • 网站建设报价清单内容成都百度推广
  • 保定市人民政府网站株洲网页设计
  • 云南城乡建设网站我们公司想做网络推广
  • 物价局网站建设情况汇报免费网站建设
  • 深圳网站设计建设郑州seo网站有优化
  • 网站建设如何添加咨询网页模板免费下载
  • 手机网站源程序百度在线问答
  • 合肥哪家公司做网站靠谱免费sem工具
  • 网站备案授权书范本自动点击器永久免费版
  • wordpress 爬虫嘉兴网站建设方案优化
  • 最便宜做网站的方法百度开放平台
  • 做网站公司哪家公司好百度大数据分析
  • 网站建设代理平台怎么做公司建网站流程
  • 建设银行投资网站首页seo综合优化公司
  • 村委会网站源码北京债务优化公司
  • html个人网站设计模板最佳的资源搜索引擎
  • 如果我的网站被百度收录了_以后如何做更新争取更多收录搜索引擎入口
  • 做母婴的网站有哪些友妙招链接
  • 分类信息网站做推广投广告哪个平台好
  • 上饶做网站公司北京百度网讯科技有限公司