随机IO读取 [英] Random IO Read

查看:67
本文介绍了随机IO读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


以下代码生成文件。你知道如何为多用户访问编写一个随机的文件代码吗?


我们想要测试FileSystem IO性能。


#include< fcntl.h>

#include< stdio.h>

#include< unistd.h>


#define FAIL -1

#define BSIZE 8192

#define FSIZE 5000


int writeit(int);

int main(void)

{

if(-1 == writeit(FSIZE))printf(" ;文件操作失败\ nn);

}


int writeit(int blocks)

{

char buf [BSIZE];

int fdes;

int i;

int written;

if((fdes = open(&.;。/ testfile.bm",O_WRONLY | O_CREAT,0777))< 0)

返回FAIL;

for(i = 0; i< blocks; i ++)

{

if(write = write(fdes,buf,BSIZE)!= BSIZE)return FAIL;

}

返回0;

}

解决方案

moonhkt写道:


大家好


以下代码生成文件。你知道如何为多用户访问编写一个随机的文件代码吗?


我们想要测试FileSystem IO性能。


#include< fcntl.h>

#include< stdio.h>

#include< unistd.h>


#define FAIL -1

#define BSIZE 8192

#define FSIZE 5000


int writeit(int);

int main(void)

{

if(-1 == writeit(FSIZE))printf(" ;文件操作失败\ nn);

}


int writeit(int blocks)

{

char buf [BSIZE];

int fdes;

int i;

int written;

if((fdes = open(&.;。/ testfile.bm",O_WRONLY | O_CREAT,0777))< 0)

返回FAIL;

for(i = 0; i< blocks; i ++)

{

if(write = write(fdes,buf,BSIZE)!= BSIZE)return FAIL;

}

返回0;

}


你将在comp.unix.programmer中得到更好的服务,因为你的代码是UNIX

具体且几乎不是标准C.


2008年4月24日星期四14:35:35 +0530,santosh< sa ********* @ gmail.com>

写道:


> moonhkt写道:


>大家好



忽略你的非标准函数和标题,你的问题好像是如何用BSIZE随机字符填充buf 。一种方法是:

将buf更改为unsigned char。

调用srand来播放rand函数。

在一个循环中,调用rand并存储它返回的int的某些部分

current buf的元素。


>>
我们要测试FileSystem IO的性能。



合理的担心IO性能会受到涉及位模式的影响吗?如果buf

与0xa5一起提交,结果会有什么不同吗?如果存在差异,那么5000个字符足够

是否会被注意到(或测量)?


>>
#include< fcntl.h>
#include< stdio.h>
#include< unistd.h>

#define FAIL -1
#define BSIZE 8192
#define FSIZE 5000
int writeit(int);
int main(void)
{
if(-1 == writeit(FSIZE))printf(FILE OPERATION FAILED\ n);
}
int writeit(int blocks)
{
char buf [BSIZE];
int fdes;
int i;
int written;
if((fdes = open(&.;。/ testfile.bm" ;,O_WRONLY | O_CREAT,0777))< 0)
返回FAIL;
for(i = 0; i< blocks; i ++)
{
if(written = write (fdes,buf,BSIZE)!= BSIZE)返回失败;
}
返回0;
}


你会得到更好的服务在comp.unix.programmer中,因为你的代码是UNIX特定的,几乎不是标准的C 。



删除电子邮件的del


moonhkt写道:


大家好


以下代码生成文件。你知道如何为多用户访问编写一个随机的文件代码吗?


我们想要测试FileSystem IO性能。



如果你想这样做,可以使用为此任务设计的许多工具之一。


-

Ian Collins。


Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

We want testing FileSystem IO performance.

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FAIL -1
#define BSIZE 8192
#define FSIZE 5000

int writeit(int);
int main(void)
{
if ( -1 == writeit(FSIZE)) printf("FILE OPERATION FAILED\n");
}

int writeit(int blocks)
{
char buf[BSIZE];
int fdes;
int i;
int written;
if ( (fdes = open("./testfile.bm",O_WRONLY|O_CREAT,0777)) < 0)
return FAIL;
for (i=0;i< blocks ; i++)
{
if (written = write(fdes,buf,BSIZE) != BSIZE) return FAIL;
}
return 0;
}

解决方案

moonhkt wrote:

Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

We want testing FileSystem IO performance.

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FAIL -1
#define BSIZE 8192
#define FSIZE 5000

int writeit(int);
int main(void)
{
if ( -1 == writeit(FSIZE)) printf("FILE OPERATION FAILED\n");
}

int writeit(int blocks)
{
char buf[BSIZE];
int fdes;
int i;
int written;
if ( (fdes = open("./testfile.bm",O_WRONLY|O_CREAT,0777)) < 0)
return FAIL;
for (i=0;i< blocks ; i++)
{
if (written = write(fdes,buf,BSIZE) != BSIZE) return FAIL;
}
return 0;
}

You''ll be better served in comp.unix.programmer as your code is UNIX
specific and hardly standard C.


On Thu, 24 Apr 2008 14:35:35 +0530, santosh <sa*********@gmail.com>
wrote:

>moonhkt wrote:

>Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

Ignoring your non-standard functions and headers, your problem seems
to be how to fill buf with BSIZE random char. One method would be to:
Change buf to unsigned char.
Call srand to seed the rand function.
In a loop, call rand and store some part of the int it returns in
the "current" element of buf.

>>
We want testing FileSystem IO performance.

Is it a reasonable concern that IO performance would be affected by
the bit patterns involved? Would the results be any different if buf
were filed with 0xa5? If there is a difference, is 5000 char enough
for it to be noticed (or measured)?

>>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define FAIL -1
#define BSIZE 8192
#define FSIZE 5000

int writeit(int);
int main(void)
{
if ( -1 == writeit(FSIZE)) printf("FILE OPERATION FAILED\n");
}

int writeit(int blocks)
{
char buf[BSIZE];
int fdes;
int i;
int written;
if ( (fdes = open("./testfile.bm",O_WRONLY|O_CREAT,0777)) < 0)
return FAIL;
for (i=0;i< blocks ; i++)
{
if (written = write(fdes,buf,BSIZE) != BSIZE) return FAIL;
}
return 0;
}


You''ll be better served in comp.unix.programmer as your code is UNIX
specific and hardly standard C.


Remove del for email


moonhkt wrote:

Hi All

Below coding for generate a file. Do you know how to write a code for
random a a file for multi-user access ?

We want testing FileSystem IO performance.

If you want to do that, use one of the many tools that have been
designed for this task.

--
Ian Collins.


这篇关于随机IO读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆