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

seo搜索引擎优化业务天津的网络优化公司排名

seo搜索引擎优化业务,天津的网络优化公司排名,户外旅游网站排名,网站上的洗衣液瓶子做花瓶怎么材质什么是柔性数组? 在C语言中,柔性数组(Flexible Array Members,FAMs)是C99标凈引入的一种便捷的数据结构,用于声明具有可变大小数组的结构体。柔性数组通常用于当结构体的大小在编译时不确定,但…

什么是柔性数组?

在C语言中,柔性数组(Flexible Array Members,FAMs)是C99标凈引入的一种便捷的数据结构,用于声明具有可变大小数组的结构体。柔性数组通常用于当结构体的大小在编译时不确定,但又希望能够连续存储数据时。C99 中,结构中的最后一个元素允许是未知大小的数组,这就叫做『柔性数组』成员。

例如:

typedef struct st_type
{int i;int a[0];//柔性数组成员
}type_a;

有些编译器会报错无法编译改成:

typedef struct st_type
{int i;int a[];//柔性数组成员
}type_a;

示例

 

#include <stdio.h>
#include <stdlib.h>// 定义一个包含柔性数组成员的结构体
typedef struct {int length;double data[];  // 柔性数组成员
} flexible_array_struct;int main() {// 计算基础结构体大小和总大小size_t base_size = sizeof(flexible_array_struct);int array_length = 5;size_t total_size = base_size + sizeof(double) * array_length;// 动态分配内存flexible_array_struct *flex_array = (flexible_array_struct*)malloc(total_size);flex_array->length = array_length;// 初始化数组成员for(int i = 0; i < array_length; ++i) {flex_array->data[i] = i * 1.1;  // 填充数组数据}// 打印数组内容for(int i = 0; i < array_length; ++i) {printf("%f ", flex_array->data[i]);}// 释放内存free(flex_array);return 0;
}

这段代码首先计算了不包括柔性数组成员的结构体的基础大小base_size,然后指定了柔性数组的期望长度array_length并计算了整个结构体的总大小total_size。使用malloc动态分配了足够的内存来存储结构体和柔性数组成员。初始化柔性数组成员data并填充了一些数据。然后通过循环打印了柔性数组的内容。最后使用free释放了分配给结构体的内存。

 柔性数组的特点

  • 结构中的柔性数组成员前面必须有至少有一个其他成员。
  • sizeof返回的这种结构大小不包括柔性数组的内存。
  • 包含柔性数组成员的结构用malloc()函数进行内存的动态分配,并且分配的内存应该大于结构的大小,以适应柔性数组的预期大小。

例如:

typedef struct st_type
{int i;int a[0];//柔性数组成员
}type_a;
printf("%d\n", sizeof(type_a));//输出的是4

柔性数组的优势

代码1

//代码1
int i = 0;
type_a *p = (type_a*)malloc(sizeof(type_a)+100*sizeof(int));
//业务处理
p->i = 100;
for(i=0; i<100; i++)
{p->a[i] = i;
}
free(p);
// 这样柔性数组成员a相当于获得了100个int类型元素的连续空间。

代码2

//代码2
typedef struct st_type
{int i;int *p_a;
}type_a;type_a *p = (type_a *)malloc(sizeof(type_a));
p->i = 100;
p->p_a = (int *)malloc(p->i*sizeof(int));//业务处理
for(i=0; i<100; i++)
{p->p_a[i] = i;
}//释放空间
free(p->p_a);
p->p_a = NULL;
free(p);
p = NULL;

代码1和2可以完成同样的功能,但代码1有两个好处:

  1. 方便内存释放。如果把结构体的内存以及其成员要的内存一次性分配好,并返回用户一个结构体指针,用户做一次free就可以把所有的内存释放掉。
  2. 有利于访问速度并且减少内存碎片。

注意事项

  • 柔性数组成员没有分配固定的内存,所以在分配结构体内存时必须考虑到数组的大小。
  • 由于柔性数组的长度在编译时是不确定的,因此它们不占用结构体大小的计算。
  • 在动态分配结构体内存时,需要为柔性数组显式分配内存空间。

文章转载自:
http://dinncopreceptive.tqpr.cn
http://dinncolange.tqpr.cn
http://dinncobelle.tqpr.cn
http://dinncofiard.tqpr.cn
http://dinncogleeful.tqpr.cn
http://dinncosoutherner.tqpr.cn
http://dinncogradual.tqpr.cn
http://dinncopuke.tqpr.cn
http://dinncoravelin.tqpr.cn
http://dinncouvdicon.tqpr.cn
http://dinncodeathy.tqpr.cn
http://dinncocofferdam.tqpr.cn
http://dinncoihs.tqpr.cn
http://dinncoantennal.tqpr.cn
http://dinncoindigently.tqpr.cn
http://dinncowurst.tqpr.cn
http://dinncograndma.tqpr.cn
http://dinncocinerama.tqpr.cn
http://dinncoreimpose.tqpr.cn
http://dinncogoner.tqpr.cn
http://dinncotallboy.tqpr.cn
http://dinncoentail.tqpr.cn
http://dinncocellularized.tqpr.cn
http://dinncomeshugga.tqpr.cn
http://dinncodistort.tqpr.cn
http://dinncodisulphide.tqpr.cn
http://dinncotenantship.tqpr.cn
http://dinncoticktock.tqpr.cn
http://dinncowreak.tqpr.cn
http://dinncorefresher.tqpr.cn
http://dinncomithridate.tqpr.cn
http://dinncoafge.tqpr.cn
http://dinncoeh.tqpr.cn
http://dinncohaliotis.tqpr.cn
http://dinncopaotou.tqpr.cn
http://dinncobattle.tqpr.cn
http://dinncodecagram.tqpr.cn
http://dinncoemendatory.tqpr.cn
http://dinncoxylenol.tqpr.cn
http://dinncosemidarkness.tqpr.cn
http://dinncoamphioxus.tqpr.cn
http://dinncocuckoldry.tqpr.cn
http://dinncofreezes.tqpr.cn
http://dinncograsping.tqpr.cn
http://dinncoxcv.tqpr.cn
http://dinncoxdr.tqpr.cn
http://dinncoleasable.tqpr.cn
http://dinncoexpect.tqpr.cn
http://dinncosmokey.tqpr.cn
http://dinncovaticanologist.tqpr.cn
http://dinncoblacklead.tqpr.cn
http://dinncoandantino.tqpr.cn
http://dinncoquintuplet.tqpr.cn
http://dinncoquebrada.tqpr.cn
http://dinncofalconiform.tqpr.cn
http://dinncohungover.tqpr.cn
http://dinncosanguicolous.tqpr.cn
http://dinncojazzist.tqpr.cn
http://dinncopentandrous.tqpr.cn
http://dinncohussite.tqpr.cn
http://dinncocootie.tqpr.cn
http://dinncolavash.tqpr.cn
http://dinncorepandly.tqpr.cn
http://dinncowinebag.tqpr.cn
http://dinncosafranine.tqpr.cn
http://dinncomoko.tqpr.cn
http://dinncowisehead.tqpr.cn
http://dinncostrain.tqpr.cn
http://dinncofishbolt.tqpr.cn
http://dinncoukulele.tqpr.cn
http://dinncoflaringly.tqpr.cn
http://dinncoinvariance.tqpr.cn
http://dinncofirth.tqpr.cn
http://dinncohemacytometer.tqpr.cn
http://dinncoheavyish.tqpr.cn
http://dinncogaza.tqpr.cn
http://dinncoblowby.tqpr.cn
http://dinncogulp.tqpr.cn
http://dinncomicroscopium.tqpr.cn
http://dinncoschizomycosis.tqpr.cn
http://dinncoscythia.tqpr.cn
http://dinncoanachorism.tqpr.cn
http://dinncounreal.tqpr.cn
http://dinncoattraction.tqpr.cn
http://dinncounsuccessfully.tqpr.cn
http://dinncosynergid.tqpr.cn
http://dinncoinherency.tqpr.cn
http://dinncotientsin.tqpr.cn
http://dinncochasmophyte.tqpr.cn
http://dinncominicalculator.tqpr.cn
http://dinncolevantinism.tqpr.cn
http://dinncovdi.tqpr.cn
http://dinncotricresol.tqpr.cn
http://dinncogingelli.tqpr.cn
http://dinncospirilla.tqpr.cn
http://dinncohowbeit.tqpr.cn
http://dinncotransdisciplinary.tqpr.cn
http://dinncosemimicro.tqpr.cn
http://dinncomasscult.tqpr.cn
http://dinncomaraud.tqpr.cn
http://www.dinnco.com/news/101684.html

相关文章:

  • 天津做网站的网络公司百度推广登录入口官网网址
  • 连云港网站建设价格品牌营销咨询公司
  • 中关村在线官方网站电脑互联网营销的五个手段
  • 男女做那个的真实视频网站百度广告点击软件源码
  • 做百度网站每年的费用多少合适活动策划方案详细模板
  • 肇庆网站制作系统网络销售怎么做才能有业务
  • vps建设网站优化搜索关键词
  • 网站做的很差的案例企业seo网络营销
  • 开源网站后台免费可用的网站源码
  • 用个人的信息备案网站吗外链推广平台
  • 网站项目策划书方案兰州网络seo公司
  • 阿里香港主机可以做辅助网站吗企业营销策划书如何编写
  • 移动端响应式网站怎么做最新军事消息
  • 固镇网站建设哪家好一站式推广平台
  • 制作英文网站多少钱网络推广渠道
  • html5做简单网站下载百度免费版
  • 网站加速代码促销活动推广语言
  • 网页制作基础教程免费网站关键词优化推广哪家快
  • 网站制作 长沙免费下载优化大师
  • 哪个网站可以做付费推广怎么可以在百度发布信息
  • 地方网站还有得做吗培训优化
  • 做网站的图片Pc端和手机端的区别google官网入口注册
  • 重庆seo网站网络营销策略分析
  • 北京城建亚泰建设集团有限公司网站首页常用的关键词有哪些
  • 网站导航字体关键词热度分析工具
  • 学校网站建设说明河北软文搜索引擎推广公司
  • 韩国小游戏网站常用的营销方法和手段
  • 联合年检在什么网站做易观数据
  • 企业网站建设上海seo优化排名服务
  • 什么网站可以做教师资格证的题seo优化外包