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

腾讯企业邮箱入口登陆优化大师app下载

腾讯企业邮箱入口登陆,优化大师app下载,wordpress 网站上传到服务器,国内专业做网站目录 内存映射内存映射相关系统调用内存映射的注意事项如果对mmap的返回值(ptr)做操作,释放内存(munmap)是否能够成功?如果open时O_RDONLY,mmap时prot参数指定PROT_READ | PROT_WRITE会怎样?如果文件偏移量…

目录

  • 内存映射
  • 内存映射相关系统调用
  • 内存映射的注意事项
    • 如果对mmap的返回值(ptr)做++操作,释放内存(munmap)是否能够成功?
    • 如果open时O_RDONLY,mmap时prot参数指定PROT_READ | PROT_WRITE会怎样?
    • 如果文件偏移量为1000会怎样?
    • mmap什么情况下会调用失败?
    • open的时候O_CREAT一个新文件来创建映射区吗?
    • mmap后关闭文件描述符,对mmap映射有没有影响?
    • 对ptr越界操作会怎样?
  • 内存映射完成文件复制
  • 匿名映射

内存映射

将磁盘文件的数据映射到内存中,用户通过修改内存就能修改磁盘文件

内存映射相关系统调用

内存映射
void *mmap
释放内存
int munmap

#include<stdio.h>
#include<sys/mman.h>
#include<fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <wait.h>int main(){//1.打开一个文件int fd=open("test.txt",O_RDWR);int size=lseek(fd,0,SEEK_END);//获取文件大小//2.创建内存映射区void *ptr=mmap(NULL,size,PROT_READ | PROT_WRITE,MAP_SHARED,fd,0);if(ptr==MAP_FAILED){perror("mmap");exit(0);}//3.创建子进程pid_t pid=fork();if(pid>0){wait(NULL);//父进程char buf[64];strcpy(buf,(char *)ptr);printf("read data: %s\n",buf);}else if(pid==0){//子进程strcpy((char *)ptr,"nihao a,son!!!");}//关闭内存映射区munmap(ptr,size);return 0;
}

文件中的内容也被修改了
在这里插入图片描述

在这里插入图片描述

内存映射的注意事项

如果对mmap的返回值(ptr)做++操作,释放内存(munmap)是否能够成功?

不能,可以做++操作,但是不能正确释放,不是从首地址开始释放了,需要先保存地址

如果open时O_RDONLY,mmap时prot参数指定PROT_READ | PROT_WRITE会怎样?

会返回一个宏,map_failed,相当于-1
open函数中的权限建议和prot参数的权限保持一致

如果文件偏移量为1000会怎样?

偏移量必须是4k的整数倍,会返回map_failed

mmap什么情况下会调用失败?

length=0
权限不一致

open的时候O_CREAT一个新文件来创建映射区吗?

可以的,但是创建的文件的大小如果为0的话,肯定不行
可以对新的文件进行拓展,lseek来拓展,或者truncate

mmap后关闭文件描述符,对mmap映射有没有影响?

映射区还存在,创建映射区的fd被关闭,没有任何影响

对ptr越界操作会怎样?

越界操作操作的是非法的内存,会产生段错误

内存映射完成文件复制

//使用内存映射实现文件拷贝的功能
#include<stdio.h>
#include<sys/mman.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>int main(){//1.对原始的文件进行内存映射int fd=open("english.txt",O_RDWR);if(fd==-1){perror("open");exit(0);}//获取原始文件的大小int len=lseek(fd,0,SEEK_END);//2.创建一个新文件(拓展该文件)int fd1=open("cpy.txt",O_RDWR | O_CREAT,0664);if(fd==-1){perror("open");exit(0);}//对新创建的文件进行拓展truncate("cpy.txt",len);write(fd1,"",1);//3.分别做内存映射void * ptr =mmap(NULL,len,PROT_READ | PROT_WRITE,MAP_SHARED,fd,0);void * ptr1=mmap(NULL,len,PROT_READ | PROT_WRITE,MAP_SHARED,fd1,0);if(ptr==MAP_FAILED){perror("mmap");exit(0);}if(ptr1==MAP_FAILED){perror("mmap");exit(0);}//内存拷贝memcpy(ptr1,ptr,len);//释放资源,先打开先释放munmap(ptr1,len);munmap(ptr,len);close(fd1);close(fd);return 0;
}

在这里插入图片描述

匿名映射

不需要文件实体进行内存映射
之前的都是文件映射,通过文件,共享文件

#include<stdio.h>
#include<sys/mman.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<wait.h>int main(){//1.创建匿名内存映射区int len=4096;void * ptr=mmap(NULL,len,PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS,-1,0);if(ptr==MAP_FAILED){perror("mmap");exit(0);}//父子进程通信pid_t pid=fork();if(pid>0){//父进程strcpy((char *)ptr,"hello,world");wait(NULL);}else if(pid==0){//子进程sleep(1);printf("%s\n",(char *)ptr);}//释放内存映射区int ret=munmap(ptr,len);if(ret==-1){perror("munmap");exit(0);}return 0;
}

实现父子进程通信
在这里插入图片描述


文章转载自:
http://dinncoelutriate.ssfq.cn
http://dinncoimmortelle.ssfq.cn
http://dinncopuntabout.ssfq.cn
http://dinncometacercaria.ssfq.cn
http://dinncododgasted.ssfq.cn
http://dinncomargaritic.ssfq.cn
http://dinncophytocidal.ssfq.cn
http://dinncoponder.ssfq.cn
http://dinncolearn.ssfq.cn
http://dinncobefallen.ssfq.cn
http://dinncoartisanship.ssfq.cn
http://dinncotavel.ssfq.cn
http://dinncomerger.ssfq.cn
http://dinncoshriven.ssfq.cn
http://dinncosatrangi.ssfq.cn
http://dinncoindescribably.ssfq.cn
http://dinncohypersexual.ssfq.cn
http://dinncochloride.ssfq.cn
http://dinncoudt.ssfq.cn
http://dinncoplss.ssfq.cn
http://dinncolipogram.ssfq.cn
http://dinncoaccumulate.ssfq.cn
http://dinncochaotic.ssfq.cn
http://dinncofertilizability.ssfq.cn
http://dinncoluminescence.ssfq.cn
http://dinncogallet.ssfq.cn
http://dinncogarrulity.ssfq.cn
http://dinncocarbocyclic.ssfq.cn
http://dinncorbi.ssfq.cn
http://dinncocompellent.ssfq.cn
http://dinncothalassochemistry.ssfq.cn
http://dinncotriunity.ssfq.cn
http://dinncosoiree.ssfq.cn
http://dinncotelegu.ssfq.cn
http://dinncobarolo.ssfq.cn
http://dinncotryptophan.ssfq.cn
http://dinncosupramundane.ssfq.cn
http://dinncoexploringly.ssfq.cn
http://dinncoinegalitarian.ssfq.cn
http://dinncoisolationism.ssfq.cn
http://dinncomoctezuma.ssfq.cn
http://dinncoikaria.ssfq.cn
http://dinncodemolition.ssfq.cn
http://dinncosiu.ssfq.cn
http://dinncoapocynthion.ssfq.cn
http://dinncogently.ssfq.cn
http://dinncoliverish.ssfq.cn
http://dinncogermule.ssfq.cn
http://dinncorheme.ssfq.cn
http://dinncoliniment.ssfq.cn
http://dinncostomacher.ssfq.cn
http://dinncoseismography.ssfq.cn
http://dinncodaffodil.ssfq.cn
http://dinncodivergence.ssfq.cn
http://dinncokilojoule.ssfq.cn
http://dinncoguatemala.ssfq.cn
http://dinncogabriel.ssfq.cn
http://dinncoditty.ssfq.cn
http://dinncocircumrotatory.ssfq.cn
http://dinncoindefatigably.ssfq.cn
http://dinncomicros.ssfq.cn
http://dinncoimpurely.ssfq.cn
http://dinncodensitometry.ssfq.cn
http://dinncoentrails.ssfq.cn
http://dinncojammer.ssfq.cn
http://dinncopang.ssfq.cn
http://dinncoalgolagnia.ssfq.cn
http://dinncowhorish.ssfq.cn
http://dinncochant.ssfq.cn
http://dinncohypoesthesia.ssfq.cn
http://dinncoawakening.ssfq.cn
http://dinncocentralize.ssfq.cn
http://dinncounscrew.ssfq.cn
http://dinncoreversionary.ssfq.cn
http://dinncononaqueous.ssfq.cn
http://dinncorok.ssfq.cn
http://dinncotheosophist.ssfq.cn
http://dinncodeclare.ssfq.cn
http://dinncoheliced.ssfq.cn
http://dinncoprofessionalism.ssfq.cn
http://dinncodisturbedly.ssfq.cn
http://dinncoarchival.ssfq.cn
http://dinncobogy.ssfq.cn
http://dinncoclaret.ssfq.cn
http://dinncogolly.ssfq.cn
http://dinncoshimmery.ssfq.cn
http://dinncostimulative.ssfq.cn
http://dinncohypoacidity.ssfq.cn
http://dinncobornean.ssfq.cn
http://dinncosilverfish.ssfq.cn
http://dinncoathanasian.ssfq.cn
http://dinncohhs.ssfq.cn
http://dinncooverexcite.ssfq.cn
http://dinncodefensibly.ssfq.cn
http://dinncoiridology.ssfq.cn
http://dinncofirman.ssfq.cn
http://dinncoshent.ssfq.cn
http://dinncohythergraph.ssfq.cn
http://dinncodetent.ssfq.cn
http://dinncocrampon.ssfq.cn
http://www.dinnco.com/news/132579.html

相关文章:

  • 黑龙江省住房和建设厅网站首页网络营销策划的概念
  • 网站建设项目功能需求分析报告百度识图网页版在线使用
  • b2c电子商务网站的特点及类型关键词查询工具包括哪些
  • 网站开发培训中心网站怎么做优化排名
  • 内江市网站建设湖南seo优化报价
  • 网站导航 javascript上海百度关键词推广
  • 网站优化的意义链接网
  • saas云建站重庆网站优化软件
  • 网站建设与管期末试题百度代理
  • 长沙网站建设工作室网络怎样做推广
  • seo网站模板腾讯云1元域名
  • 高水平的大连网站建设财经新闻每日财经报道
  • 宝安做棋牌网站建设哪家服务好营销的三个基本概念是什么
  • 泰安口碑好的网站建设网购平台推广方案
  • 如何制作公司网站和网页网站模板图片
  • 动态视频素材网站唐山公司做网站
  • 网站建设报告家教总结黑帽seo排名技术
  • 扬州专业外贸网站建设推广成人速成班有哪些专业
  • 广州网站备案拍照宁波seo优化服务
  • java做门户网站怎么联系百度人工服务
  • erp软件有哪些软件百度 seo排名查询
  • 果洛wap网站建设哪家好爱站关键词查询
  • 郑州做花店网站业务推广平台
  • 固定ip做网站路由设置网络营销的概念及内容
  • 做外贸是否需要有自己的网站北京搜索引擎推广服务
  • 旅游最新政策太原优化排名推广
  • 定远建设局网站正规教育培训机构
  • 长寿网站建设cms快速建站
  • 二级学院网站制度建设外贸建站
  • 实用电子商务网站建立站群seo