读写者问题(8)

2019-02-20 20:34

山东科技大学学生课程设计

tick = GetTickCount();

filter_sequen(\

cout<<\ tick = GetTickCount();

filter_sequen(\ DWORD sequen_end_time = GetTickCount();

cout<<\ cout<<\异步传输模式正在运行...\ DWORD overlp_start_time = GetTickCount();

tick = overlp_start_time;

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\

cout<<\

山东科技大学学生课程设计

tick = GetTickCount();

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\

cout<<\ tick = GetTickCount();

filter_overlp(\ DWORD overlp_end_time = GetTickCount();

cout<<\ // 输出3种模式下的平均时间做对比

cout<<\种模式的平均用时如下:\ cout<<\无文件高速缓存模式平均用时:\

<<(nobuffer_end_time - nobuffer_start_time)/10<<\ cout<<\使用高速文件缓存模式平均用时:\

<<(sequen_end_time - sequen_start_time)/10<<\ cout<<\异步传输模式平均用时:\

<<(overlp_end_time - overlp_start_time)/10<<\ return; }

// -------------------------------------------------------------- // 对文件内容进行的5种操作 // f1 +1 // f2 -1 // f3 *1 // f4 >> // f5 <<

void f1(char *addr){ *addr = (unsigned char)*addr + 1;} void f2(char *addr){ *addr = (unsigned char)*addr - 1;} void f3(char *addr){ *addr = (unsigned char)*addr * 1;} void f4(char *addr){ *addr = (unsigned char)*addr >> 1;} void f5(char *addr){ *addr = (unsigned char)*addr << 1;} // --------------------------------------------------------------

// 没有文件高速缓存的filter函数

void filter_nobuffer(char *source, char *sink, void (*func) (char

山东科技大学学生课程设计

*addr)) {

HANDLE handle_src, handle_dst; // handles of source file and destination file BOOL cycle;

DWORD NumberOfBytesRead, NumberOfBytesWrite, index; // open the source file

handle_src = CreateFile(source, GENERIC_READ, NULL, NULL,

OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); handle_dst = CreateFile(sink, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, NULL, NULL);

if(handle_src == INVALID_HANDLE_VALUE || handle_dst == INVALID_HANDLE_VALUE) {

cout<<\ exit(1); }

cycle = TRUE;

// use cycle to know when we finished reading the file while(cycle) {

// read data and send them into buffer from the source file if(ReadFile(handle_src, buffer, BUFFER_SIZE, &NumberOfBytesRead, NULL) == FALSE) {

cout<<\ exit(1); }

if(NumberOfBytesRead < BUFFER_SIZE) cycle = FALSE;

// do the operation to the file

for(index = 0; index < NumberOfBytesRead; index ++) func(&buffer[index]);

山东科技大学学生课程设计

// write the content of the buffer to the destination file if(WriteFile(handle_dst, buffer, NumberOfBytesRead, &NumberOfBytesWrite, NULL) == FALSE) {

cout<<\ exit(1); } }

// close the file handle CloseHandle(handle_src); CloseHandle(handle_dst); }

void filter_sequen(char *source, char *sink, void (*func) (char *addr)) {

HANDLE handle_src, handle_dst; // handles of source file and destination file BOOL cycle;

DWORD NumberOfBytesRead, NumberOfBytesWrite, index; // open the source file

handle_src = CreateFile(source, GENERIC_READ, NULL, NULL,

OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);

handle_dst = CreateFile(sink, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL);

if(handle_src == INVALID_HANDLE_VALUE || handle_dst == INVALID_HANDLE_VALUE) {

cout<<\ exit(1); }

cycle = TRUE;

// use cycle to know when we finished reading the file while(cycle)

山东科技大学学生课程设计

{

// read data and send them into buffer from the source file if(ReadFile(handle_src, buffer, BUFFER_SIZE, &NumberOfBytesRead, NULL) == FALSE) {

cout<<\ exit(1); }

if(NumberOfBytesRead < BUFFER_SIZE) cycle = FALSE;

// do the operation to the file

for(index = 0; index < NumberOfBytesRead; index ++) func(&buffer[index]);

// write the content of the buffer to the destination file if(WriteFile(handle_dst, buffer, NumberOfBytesRead, &NumberOfBytesWrite, NULL) == FALSE) {

cout<<\ exit(1); } }

// close the file handle CloseHandle(handle_src); CloseHandle(handle_dst); }

void filter_overlp(char *source, char *sink, void (*func) (char *addr)) {

HANDLE handle_src, handle_dst; // handles of source file and destination file BOOL cycle;

DWORD NumberOfBytesRead, NumberOfBytesWrite, index, dwError;

OVERLAPPED overlapped; // overlapped 结构 // open the source file

handle_src = CreateFile(source, GENERIC_READ, NULL,


读写者问题(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:(北师大版)五年级数学上册知识点归纳讲解

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: