Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7190792
  • 博文数量: 510
  • 博客积分: 12019
  • 博客等级: 上将
  • 技术积分: 6836
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-01 16:46
文章分类

全部博文(510)

文章存档

2022年(2)

2021年(6)

2020年(59)

2019年(4)

2018年(10)

2017年(5)

2016年(2)

2015年(4)

2014年(4)

2013年(16)

2012年(47)

2011年(65)

2010年(46)

2009年(34)

2008年(52)

2007年(52)

2006年(80)

2005年(22)

分类: LINUX

2005-08-01 17:51:50

try opening the file with O_DIRECT in the flags.
O_DIRECT allows reads and writes to avoid the linux fs cache

举例;

#include
#include
#include
#include
#include

unsigned long long get_sys_time();
int main(int argc,char*argv[])
{
int i;
int nRet=0;
if(argc!=3)
{
printf("Usage:pro file size ");
return 0;
}
unsigned long long llBeg =0;
unsigned long long llEnd =0;
int fp;
int nLen = atoi(argv[2]);

char *pBuf = (char*)calloc(1,nLen);
llBeg = get_sys_time();
fp = open(argv[1],O_RDONLY,O_DIRECT);
assert(fp>0);
memset(pBuf,0,nLen);
nRet = read(fp,pBuf,nLen);
close(fp);
llEnd = get_sys_time();
free(pBuf);
printf("readed=%d ",nRet);
printf("elapsed time:=%d ",(llEnd-llBeg)/1000);
return 0;

}


阅读(3189) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~