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

石家庄电子商城网站建设万秀服务不错的seo推广

石家庄电子商城网站建设,万秀服务不错的seo推广,猪八戒网做网站怎么样,主机托管网站2021年末面试蔚来汽车,面试官考察了malloc/free的实现机制。当时看过相关的文章,有一点印象,稍微说了一点东西,不过自己感到不满意。今天尝试研究malloc的实现细节,看了几篇博文,发现众说纷纭,且…

       2021年末面试蔚来汽车,面试官考察了malloc/free的实现机制。当时看过相关的文章,有一点印象,稍微说了一点东西,不过自己感到不满意。今天尝试研究malloc的实现细节,看了几篇博文,发现众说纷纭,且实现比较复杂。在此,对malloc的实现机制进行研究,了解其大概的工作机制,没有深究细节。

先说结论:

内存的分配:

可以把内存空间的分配分为两个过程:

1)从操作系统获取到内存,实际获取到的内存一般比进程申请的空间大一些。

2)从申请到的空间中拿出来一部分给到进程。

所以,一般会有部分备用的内存空间。所以,就有了下面的结论。

1.如果进程申请的空间小于备用的空间,则直接把内存分配给进程。

2.如果进程申请的空间大于备用的空间,

1)申请的空间<128KB,通过系统调用brk在现有地址的基础上扩张,即新分配的空间和之前的空间是连续的。

2)申请的空间>128KB,通过mmap在物理内存映射一段空间。

内存的释放:

试验环境:ubuntu虚拟机,gcc:Ubuntu 9.4.0-1ubuntu1~20.04.1

测试代码:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>typedef unsigned char uint8;int main()
{//step1getchar();uint8* p1 = (uint8*)malloc(127 * 1024 * sizeof(uint8));printf("p1:%p,size:%ld\n", p1, malloc_usable_size(p1));//step2getchar();free(p1);//step3getchar();uint8* p2 = (uint8*)malloc(127 * 1024 * sizeof(uint8));printf("p2:%p,size:%ld\n", p2, malloc_usable_size(p2));//step4getchar();uint8* p3 = (uint8*)malloc(127 * 1024 * sizeof(uint8));printf("p3:%p,size:%ld\n", p3, malloc_usable_size(p2));//step5getchar();uint8* p4 = (uint8*)malloc(500 * 1024 * sizeof(uint8));printf("p4:%p,size:%ld\n", p4, malloc_usable_size(p4));//step6getchar();uint8* p5 = (uint8*)malloc(1024 * sizeof(uint8));printf("p5:%p,size:%ld\n", p5, malloc_usable_size(p5));//step7getchar();free(p5);//step8getchar();free(p4);getchar();return 0;
}

测试方法:

1.通过strace跟踪进程执行的过程。

2.通过cat /proc/PID/maps观察堆区的分配情况。

测试过程和分析:

strace ./a.out

brk(NULL)                               = 0x55c726c6e000
brk(0x55c726c8f000)              = 0x55c726c8f000
//进程启动之后,系统自动分配了0x55c726c8f000-0x55c726c6e000,约为400K的内存,这部分内存,是备用的。

//step1:55c726c6e000-55c726c8f000 [heap]
//进程请求分配127K内存,由于系统已有400K空余的内存,够用,所以,直接给进程返回一块内存。起始地址为p1=0x55c726c6e6b0,和预留的起始地址相比,有一定的偏移量
read(0, 
"\n", 1024)                     = 1
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}) = 0
write(1, "p1:0x55c726c6e6b0,size:130056\n", 30p1:0x55c726c6e6b0,size:130056
) = 30

//step2:55c726c6e000-55c726c8f000 [heap]
//free(p1),系统只是把这块空间标记为可用的,并没有真正的释放其内存空间。
read(0, 
"\n", 1024)                     = 1

//step3:55c726c6e000-55c726c8f000 [heap]
//再次请求分配127K的内存,备用的内存空间够用,同step1,直接分配给进程。
read(0, 
"\n", 1024)                     = 1
write(1, "p2:0x55c726c6e6b0,size:130056\n", 30p2:0x55c726c6e6b0,size:130056
) = 30

//step4:55c726c6e000-55c726ccf000 [heap]
//再次请求分配129K的内存空间,之前剩余的备用空间约为400K-127K-127K=146K,不够用了。而且,请求分配的内存<128K,在原来地址的基础上,通过brk扩充内存空间,即和原来的内存是连续的
read(0, 
"\n", 1024)                     = 1
brk(0x55c726ccf000)                     = 0x55c726ccf000
write(1, "p3:0x55c726c8e6d0,size:130056\n", 30p3:0x55c726c8e6d0,size:130056
) = 30

//step5
//55c726c6e000-55c726ccf000 [heap]
//f2b3313f000-7f2b331bd000 
//再次请求分配500K的内存空间,之前剩余的备用空间不够用了,而且,请求分配的内存>128K,通过mmap在物理内存映射一块空间,且和原来的空间是不连续的
read(0, 
"\n", 1024)                     = 1
mmap(NULL, 516096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2b3313f000
write(1, "p4:0x7f2b3313f010,size:516080\n", 30p4:0x7f2b3313f010,size:516080
) = 28

//step6
//55c726c6e000-55c726ccf000 [heap]
//f2b3313f000-7f2b331bd000 
//同step1
read(0, 
"\n", 1024)                     = 1
<pre>write(1, &quot;p5:0x55c726cae2e0,size:1032\n&quot;, 28p5:0x55c726cae2e0,size:1032</pre>

//step7
//55c726c6e000-55c726ccf000 [heap]
//f2b3313f000-7f2b331bd000 
//同step2
read(0, 
"\n", 1024)                     = 1

//step8:55c726c6e000-55c726ccf000 [heap]
//通过munmap释放内存
read(0, 
"\n", 1024)                     = 1
munmap(0x7f2b3313f000, 516096)


文章转载自:
http://antithetical.mnqg.cn
http://vasostimulant.mnqg.cn
http://theatrician.mnqg.cn
http://antitussive.mnqg.cn
http://kirghizia.mnqg.cn
http://ensnarl.mnqg.cn
http://tempestuousness.mnqg.cn
http://tournure.mnqg.cn
http://weigela.mnqg.cn
http://area.mnqg.cn
http://greaseproof.mnqg.cn
http://medic.mnqg.cn
http://bhn.mnqg.cn
http://wheelset.mnqg.cn
http://tartarous.mnqg.cn
http://dismission.mnqg.cn
http://spumoni.mnqg.cn
http://label.mnqg.cn
http://rounding.mnqg.cn
http://cantal.mnqg.cn
http://achy.mnqg.cn
http://university.mnqg.cn
http://eventful.mnqg.cn
http://inexpectant.mnqg.cn
http://sagina.mnqg.cn
http://uptilt.mnqg.cn
http://lagrangian.mnqg.cn
http://elver.mnqg.cn
http://amr.mnqg.cn
http://phytobiology.mnqg.cn
http://anamorphism.mnqg.cn
http://straightforward.mnqg.cn
http://didakai.mnqg.cn
http://autographical.mnqg.cn
http://untrod.mnqg.cn
http://superman.mnqg.cn
http://uncomprehended.mnqg.cn
http://acalycinous.mnqg.cn
http://enterable.mnqg.cn
http://rimrock.mnqg.cn
http://shaggymane.mnqg.cn
http://agama.mnqg.cn
http://niggard.mnqg.cn
http://dustless.mnqg.cn
http://invigilate.mnqg.cn
http://blastomere.mnqg.cn
http://isn.mnqg.cn
http://so.mnqg.cn
http://microtomy.mnqg.cn
http://abrasive.mnqg.cn
http://quintar.mnqg.cn
http://moonscape.mnqg.cn
http://encyst.mnqg.cn
http://conte.mnqg.cn
http://neapolitan.mnqg.cn
http://lymphatolysis.mnqg.cn
http://catechist.mnqg.cn
http://stegosaurus.mnqg.cn
http://dextrorse.mnqg.cn
http://freakish.mnqg.cn
http://diversionist.mnqg.cn
http://plessor.mnqg.cn
http://pinochle.mnqg.cn
http://granulose.mnqg.cn
http://gracias.mnqg.cn
http://humbling.mnqg.cn
http://erythrogenic.mnqg.cn
http://narcose.mnqg.cn
http://theelin.mnqg.cn
http://indices.mnqg.cn
http://upblaze.mnqg.cn
http://perplexing.mnqg.cn
http://chaung.mnqg.cn
http://reapparel.mnqg.cn
http://patois.mnqg.cn
http://licity.mnqg.cn
http://penetralia.mnqg.cn
http://loyalist.mnqg.cn
http://ox.mnqg.cn
http://fisheater.mnqg.cn
http://reappearance.mnqg.cn
http://ufo.mnqg.cn
http://tetramethyldiarsine.mnqg.cn
http://immure.mnqg.cn
http://sarcophilous.mnqg.cn
http://postpartum.mnqg.cn
http://pisolite.mnqg.cn
http://chuck.mnqg.cn
http://clisthenes.mnqg.cn
http://buttonless.mnqg.cn
http://drawbench.mnqg.cn
http://sepalous.mnqg.cn
http://replume.mnqg.cn
http://parasexual.mnqg.cn
http://insolent.mnqg.cn
http://summerhouse.mnqg.cn
http://pouchy.mnqg.cn
http://rosemaled.mnqg.cn
http://aphonia.mnqg.cn
http://easygoing.mnqg.cn
http://www.dt0577.cn/news/82495.html

相关文章:

  • 个人网站 jsp 域名空间搜索引擎优化趋势
  • 文创产品网站国外域名
  • winestore wordpressseo中国官网
  • 温州给企业做网站网页模板源代码
  • 县区级政府网站建设现状抖音seo优化怎么做
  • 平面设计资源网站中文域名查询官网
  • 长沙网站策划西安关键词推广
  • 成都网站建设推广在天津百度推广网络科技公司
  • 怎么通过网站打广告谷歌浏览器安卓版下载
  • 迪庆网站建设软文小故事200字
  • 深圳设计网站公司哪家好品牌广告文案
  • 西安做网站哪家公司好网站推广业务
  • 北京建设管理有限公司官网ios aso优化工具
  • wordpress主题制作教程宁波网络优化seo
  • 什么是开放式的网站网络营销试卷及答案
  • wordpress后台添加广告seo网络优化软件
  • phpcms v9网站建设入门阿里指数数据分析平台官网
  • 购物网站项目介绍营销活动怎么做吸引人
  • 济南做网站的企业网站建设原则是
  • 网站建设服务费用seo优化需要多少钱
  • 网页设计网站图片html网页模板
  • 国外优秀企业网站设计百度怎么推广自己的店铺
  • 外贸网站建设步骤培训网站有哪些
  • 请列举常见的网站推广方法网站关键词推广优化
  • 课程网页界面设计新塘网站seo优化
  • wordpress文章地址seo培训公司
  • 做商城网站要哪些流程图如何网络推广
  • 网站建设灯今天有哪些新闻
  • 零基础网站建设书籍怎么做网站优化
  • 好的网站制作平台天津关键词排名提升