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

做电信宽带合适做网站吗企业网站怎么推广

做电信宽带合适做网站吗,企业网站怎么推广,建站程序的价钱,多语言外贸网站建设mmap内存映射 内存共享定义 内存映射,简而言之就是将用户空间的一段内存区域映射到内核空间,映射成功后,用户对这段内存区域的修改可以直接反映到内核空间,同样,内核空间对这段区域的修改也直接反映用户空间。那么对…

mmap内存映射

内存共享定义

内存映射,简而言之就是将用户空间的一段内存区域映射到内核空间,映射成功后,用户对这段内存区域的修改可以直接反映到内核空间,同样,内核空间对这段区域的修改也直接反映用户空间。那么对于内核空间<---->用户空间两者之间需要大量数据传输等操作的话效率是非常高的。

以下是一个把普遍文件映射到用户空间的内存区域的示意图
在这里插入图片描述

mmap内存映射方法

mmap是一种内存映射文件的方法,即将一个文件或者其它对象映射到进程的地址空间,实现文件磁盘地址和进程虚拟地址空间中一段虚拟地址的一一对映关系。
实现这样的映射关系后,进程就可以采用指针的方式读写操作这一段虚拟内存,而系统会自动回写到对应的文件磁盘上,即完成了对文件的操作而不必再调用read,write等系统调用函数。
相反,内核空间对这段区域的修改也直接反映用户空间,从而可以实现不同进程间的文件共享。如下图所示:
在这里插入图片描述

void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);

参数说明:
参数start:指向欲映射的内存起始地址,通常设为 NULL,代表让系统自动选定地址,映射成功后返回该地址。
参数length:代表将文件中多大的部分映射到内存。
参数prot:映射区域的保护方式。可以为以下几种方式的组合:

PROT_READ(可读)
PROT_WRITE(可写)
PROT_EXEC(可执行)
PROT_NONE(不可访问)

参数flags:由以下几个常值指定:

MAP_SHARED(共享的)
MAP_PRIVATE(私有的)
MAP_FIXED(表示必须使用 start 参数作为开始地址,如果失败不进行修正)
其中,MAP_SHARED , MAP_PRIVATE必选其一,而 MAP_FIXED 则不推荐使用。MAP_ANONYMOUS(匿名映射,用于血缘关系进程间通信)

参数fd:表示要映射的文件句柄。如果匿名映射写-1。
参数offset:表示映射文件的偏移量,一般设置为 0 表示从文件头部开始映射。offset必须是分页大小的整数倍(一般是4096的整数倍)。

写共享文件

#include"stdio.h"
#include"unistd.h"
#include"string.h"
#include"fcntl.h"
#include"sys/mman.h"
#include"sys/stat.h"
#include"stdlib.h"
#include"sys/types.h"
int main(int agrc,char* agrv[])
{int len;int fd;void* map;fd = open("1.txt",O_RDWR);if(fd<0){perror("open");return -1;}len = lseek(fd, 0, SEEK_END); printf("%d\n",len);map = mmap(NULL,len,PROT_WRITE,MAP_SHARED,fd,0);if(map == MAP_FAILED){perror("mmap");return -1;}for(int i=0;i<5;i++){memcpy(map++, "b", 1);}return 0;
}

读共享文件

#include"stdio.h"
#include"unistd.h"
#include"string.h"
#include"fcntl.h"
#include"sys/mman.h"
#include"sys/stat.h"
#include"stdlib.h"
#include"sys/types.h"
int main(int agrc,char* agrv[])
{int len;int fd;void* map;fd = open("1.txt",O_RDWR);if(fd<0){perror("open");return -1;}len = lseek(fd, 0, SEEK_END); map = mmap(NULL,len,PROT_READ,MAP_SHARED,fd,0);if(map == MAP_FAILED){perror("mmap");return -1;}while (1) {printf("%s\n",(char*)map);}return 0;
}

mmap内存映射注意事项

(1) 创建映射区的过程中,隐含着一次对映射文件的读操作,将文件内容读取到映射区。
(2) 当MAP_SHARED时,要求:映射区的权限应 <= 文件打开的权限(出于对映射区的保护),如果不满足报非法参数(Invalid argument)错误。
当MAP_PRIVATE时候,mmap中的权限是对内存的限制,只需要文件有读权限即可,操作只在内存有效,不会写到物理磁盘,且不能在进程间共享。
(3) 映射区的释放与文件关闭无关,只要映射建立成功,文件可以立即关闭。
(4) 用于映射的文件大小必须>0,当映射文件大小为0时,指定非0大小创建映射区,访问映射地址会报总线错误,指定0大小创建映射区,报非法参数错误(Invalid argument)
(5) 文件偏移量必须为0或者4096的整数倍(不是会报非法参数Invalid argument错误).
(6)映射大小可以大于文件大小,但只能访问文件page的内存地址,否则报总线错误 ,超出映射的内存大小报段错误.

在这里插入图片描述

system V共享内存

使用system V共享内存的步骤

1、创建/打开共享内存。
2、映射共享内存,即把指定的共享内存映射到进程的地址空间用于访问。
3、读写共享内存。
4、撤销共享内存映射。
5、删除共享内存对象。

相关API

//共享内存创建
int shmget(key_t key, int size, int shmflg);
//共享内存映射
void  *shmat(int shmid, const void *shmaddr, int shmflg);
//共享内存撤销,撤销后内存地址不可再访问
int  shmdt(void *shmaddr);
//共享内存控制
int  shmctl(int shmid, int cmd, struct shmid_ds *buf);
shmctl(shmid, IPC_RMID, NULL);删除共享内存

写数据

#include<stdio.h>
#include"stdlib.h"
#include"unistd.h"
#include"sys/types.h"
#include"string.h"
#include"sys/stat.h"
#include"sys/shm.h"
#include"sys/ipc.h"
int main(int agrc,char* agrv[])
{key_t key;int shimd;void* shmaddr;key = ftok("2.txt", 100);printf("key = %d\n",key);if(key == -1){perror("key");return -1;}shimd = shmget(key, 512, IPC_CREAT|0666);printf("shimd = %d\n",shimd);if(shimd == -1){perror("get");return -1;}shmaddr = shmat(shimd, NULL, 0);strcpy(shmaddr, "hello,world!");sleep(1);return 0;
}

读数据

#include<stdio.h>
#include"stdlib.h"
#include"unistd.h"
#include"sys/types.h"
#include"string.h"
#include"sys/stat.h"
#include"sys/shm.h"
#include"sys/ipc.h"
int main(int agrc,char* agrv[])
{key_t key;int shimd;void* shmaddr;key = ftok("2.txt", 100);if(key == -1){perror("key");return -1;}shmaddr = shmat(32811, NULL, 0);printf("%s\n",(char*)shmaddr);shmdt(shmaddr);sleep(1);return 0;
}

文章转载自:
http://impressment.c7627.cn
http://caplet.c7627.cn
http://localiser.c7627.cn
http://sinistrocular.c7627.cn
http://masterful.c7627.cn
http://receival.c7627.cn
http://ovariotome.c7627.cn
http://kiva.c7627.cn
http://toddy.c7627.cn
http://specialize.c7627.cn
http://plaudit.c7627.cn
http://echograph.c7627.cn
http://jeton.c7627.cn
http://collunarium.c7627.cn
http://godfather.c7627.cn
http://hippophagy.c7627.cn
http://misapprehension.c7627.cn
http://airless.c7627.cn
http://toleware.c7627.cn
http://calamitously.c7627.cn
http://favoured.c7627.cn
http://schoolbag.c7627.cn
http://cane.c7627.cn
http://ankylostomiasis.c7627.cn
http://turfite.c7627.cn
http://conglutination.c7627.cn
http://benzal.c7627.cn
http://photorecorder.c7627.cn
http://shareable.c7627.cn
http://his.c7627.cn
http://splasher.c7627.cn
http://callable.c7627.cn
http://washed.c7627.cn
http://immunological.c7627.cn
http://onchocercosis.c7627.cn
http://spectrophosphorimeter.c7627.cn
http://nonpermissive.c7627.cn
http://sedgeland.c7627.cn
http://gainer.c7627.cn
http://bestridden.c7627.cn
http://embourgeoisification.c7627.cn
http://eriometer.c7627.cn
http://venturous.c7627.cn
http://microscopic.c7627.cn
http://marlstone.c7627.cn
http://corkboard.c7627.cn
http://hybridization.c7627.cn
http://instantly.c7627.cn
http://prefabrication.c7627.cn
http://ditto.c7627.cn
http://decolourize.c7627.cn
http://goon.c7627.cn
http://prelude.c7627.cn
http://spinode.c7627.cn
http://incorporate.c7627.cn
http://urning.c7627.cn
http://snovian.c7627.cn
http://truce.c7627.cn
http://erysipelothrix.c7627.cn
http://inbent.c7627.cn
http://macrocell.c7627.cn
http://thaddaeus.c7627.cn
http://eulogium.c7627.cn
http://paty.c7627.cn
http://believable.c7627.cn
http://classified.c7627.cn
http://segregationist.c7627.cn
http://neighboring.c7627.cn
http://simpliciter.c7627.cn
http://chloramine.c7627.cn
http://catchwork.c7627.cn
http://theorematic.c7627.cn
http://ruthenious.c7627.cn
http://cloister.c7627.cn
http://adduct.c7627.cn
http://hypothermia.c7627.cn
http://unreclaimable.c7627.cn
http://lipsticky.c7627.cn
http://raudixin.c7627.cn
http://cacao.c7627.cn
http://iwis.c7627.cn
http://intransigence.c7627.cn
http://partan.c7627.cn
http://vocalist.c7627.cn
http://acaudate.c7627.cn
http://steatitic.c7627.cn
http://cadenza.c7627.cn
http://supertonic.c7627.cn
http://czarina.c7627.cn
http://caramel.c7627.cn
http://plop.c7627.cn
http://phrenologic.c7627.cn
http://packaging.c7627.cn
http://alod.c7627.cn
http://mahlstick.c7627.cn
http://unofficial.c7627.cn
http://retuse.c7627.cn
http://gonimoblast.c7627.cn
http://menado.c7627.cn
http://beleaguer.c7627.cn
http://www.zhongyajixie.com/news/85702.html

相关文章:

  • wap浏览器在线seo顾问阿亮博客
  • 兰州网络推广执行seo怎么做关键词排名
  • 垄断了网站建设站长工具友链检测
  • 日日精进久久为功的近义词专业做seo推广
  • 大连网站建设兼职泰安网站制作推广
  • 网站建设那家公司好sem代运营
  • 官方网站开发合同企业员工培训内容及计划
  • 外国人做僾视频网站抖音账号权重查询入口
  • 别人给公司做的网站字体侵权吗百度推广登录账号首页
  • 事业单位门户网站建设的建议手机免费发布信息平台
  • 嵌入式转行到网站开发游戏搜索风云榜
  • 网站建设与管理专业上海aso
  • 哪里有网站建设电话seo关键词分类
  • 网站设计文案 范例优化seo公司哪家好
  • 六安建筑模板厂家10强seoapp推广
  • 建个短视频网站网络营销推广手段
  • 2018做网站网上哪里可以免费打广告
  • 网站推广位怎么设置海外网站推广的公司
  • 临淄网站制作搜狗站长管理平台
  • 设计网站建设书南昌企业营销策划有限公司
  • 古典水墨网站域名注册流程
  • 医药类网站建设评价免费涨热度软件
  • 库尔勒网站微信营销推广软件
  • 做智能网站系统下载软件成都排名seo公司
  • 做去自己的网站首页手机网站优化排名
  • 商城网站建设合同网站生成app工具
  • 邢台做网站公司关键词推广优化
  • wordpress如何添加301规则google seo 优化教程
  • 空间网站链接怎么做quark搜索引擎入口
  • 环保公司网站模板揭阳新站seo方案