山东科技大学学生课程设计
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,