15,471
社区成员
发帖
与我相关
我的任务
分享
int main()
{
ShareMemory sm;//一个自定义的封装内存映射类
DWORD start,ReflectTime,IOTime;
if(sm.Reflect("ShareMemory.txt",GENERIC_READ))
{
char *p=(char*)sm.GetStartAddress();//获取映射内存首地址
start=GetTickCount();//记录用内存映射读取数据开始时间
//cout<<p<<endl;//输出
int i=0;
while(*p++);
}
ReflectTime=GetTickCount()-start;//记录内存映射输出花费时间
sm.Release();
ifstream infile("ShareMemory.txt");
if(!infile.is_open())
{
cerr<<"open error!"<<endl;
}
char ch;
start=GetTickCount();//记录用IO读取内存起始时间
while(infile>>ch);
// cout<<ch;
IOTime=GetTickCount()-start;//记录IO读花费时间
infile.close();
cout<<endl<<"ReflectTime= "<<ReflectTime<<"ms"<<endl;
cout<<endl<<"IOTime= "<<IOTime<<"ms"<<endl;
return 0;
int main()
{
ShareMemory sm;//一个自己封装的内存映射类
DWORD start,ReflectTime,IOTime;
if(sm.Reflect("ShareMemory.txt",GENERIC_READ))//建立映射,包括提交物理存储器(映射整个文件)
{
char *p=(char*)sm.GetStartAddress();//获取映射内存首地址
start=GetTickCount();//记录用内存映射读取数据开始时间
cout<<p<<endl;//输出
}
ReflectTime=GetTickCount()-start;//记录内存映射输出花费时间
sm.Release();//释放操作
ifstream infile("ShareMemory.txt");
if(!infile.is_open())
{
cerr<<"open error!"<<endl;
}
char ch;
start=GetTickCount();//记录用IO读取内存起始时间
while(infile>>ch)
cout<<ch;
IOTime=GetTickCount()-start;//记录IO读花费时间
infile.close();
cout<<endl<<"ReflectTime= "<<ReflectTime<<"ms"<<endl;
cout<<endl<<"IOTime= "<<IOTime<<"ms"<<endl;
return 0;