mmap
2013-09-25 01:03
239 查看
//mmap把磁盘上文件映象到内存中。
//GNU/Linux===p259
#include<sys/types.h>
#include<sys/mman.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
void err_quit(char *msg)
{
perror(msg);
exit(EXIT_FAILURE);
}
int main(int argc,char *argv[]){
int fd;
struct stat buf;
char *src;
off_t len;
if((fd=open(argv[1],O_RDONLY))<0)
err_quit("open");
fstat(fd,&buf);
len=buf.st_size;//获得要映射文件的大小
src=mmap(0,len,PROT_READ,MAP_SHARED,fd,0);
printf("%s",src);
close(fd);
exit(EXIT_SUCCESS);
}
//GNU/Linux===p259
#include<sys/types.h>
#include<sys/mman.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
void err_quit(char *msg)
{
perror(msg);
exit(EXIT_FAILURE);
}
int main(int argc,char *argv[]){
int fd;
struct stat buf;
char *src;
off_t len;
if((fd=open(argv[1],O_RDONLY))<0)
err_quit("open");
fstat(fd,&buf);
len=buf.st_size;//获得要映射文件的大小
src=mmap(0,len,PROT_READ,MAP_SHARED,fd,0);
printf("%s",src);
close(fd);
exit(EXIT_SUCCESS);
}
相关文章推荐
- 会话之session技术(转)
- Struts2系列——struts2的result
- IIS6如何开启Gzip压缩的方法
- 不同用户导出导入时,表空间的问题
- KVC和KVO实现监听容器类(数组等)的变化
- java获取当前类的绝对路径
- flock
- 算法视频库下载常用网址(转载)
- Android中的JSON详细总结
- property_get/property_set
- zoj Candies 贪心
- 混合高斯背景建模理解(原创)
- 软件工程第一次作业词频统计
- MyEclipse使用经验总结
- IOS 正则表达式匹配文本中URL位置并获取URL所在位置(解决连接中文问题)
- JitterBuffer对POS机的影响
- Cn m 组合数,输出!
- 会话之cookie技术(转)
- linux virtualbox 访问 usb
- 黑马程序员-面向对象