在网上搜到一段代码如下:
var
s:string;
fh,hfile:Thandle;
fsize,i:integer;
pfile,f:pbyte;
begin
fh:=fileopen('d:/mytext.txt',fmopenreadwrite);
if fh=0 then
raise exception.create('无法打开');
fsize:=getfilesize(fh,nil);
hfile:=createfilemapping(fh,nil,page_readwrite,0,fsize,'myfile');
if hfile=0 then
raise exception.create('无法创建');
pfile:=mapviewoffile(hfile,file_map_all_access,0,0,fsize+length(s));
if pfile=0 then
raise exception.create('无法映射');
p:=pfile;
p:=pbyte(dword(p)+fsize);
for i:=1 to length(s) do
begin
p^:=byte(s[i]);
inc(p,1);
end;
........
end; 我看了不明白到底把什么映射到内存去了?是打开的mytext.txt吗?,还是什么??高手给我看看吧,本人正在学习中
var
s:string;
fh,hfile:Thandle;
fsize,i:integer;
pfile,f:pbyte;
begin
fh:=fileopen('d:/mytext.txt',fmopenreadwrite);
if fh=0 then
raise exception.create('无法打开');
fsize:=getfilesize(fh,nil);
hfile:=createfilemapping(fh,nil,page_readwrite,0,fsize,'myfile');
if hfile=0 then
raise exception.create('无法创建');
pfile:=mapviewoffile(hfile,file_map_all_access,0,0,fsize+length(s));
if pfile=0 then
raise exception.create('无法映射');
p:=pfile;
p:=pbyte(dword(p)+fsize);
for i:=1 to length(s) do
begin
p^:=byte(s[i]);
inc(p,1);
end;
........
end; 我看了不明白到底把什么映射到内存去了?是打开的mytext.txt吗?,还是什么??高手给我看看吧,本人正在学习中
mapviewoffile 这个才是用映射句柄在进程的地址空间映射一个文件视图
可以看这里
http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx
这个时候映射到内存的是s的内容呢?还是mytext.txt文本文件的内容???很茫然呀!这里是把S的内容写入mytext.txt里。那么反过来,我要从mytext.txt文本中用映射读出来,又怎么使用映射呢?给点可行的代码,行不??高手指点一下吧,小妹谢谢了
是不是mytext.txt文本哟。半天看不懂哎。哥,能给点可行的代码吗?指针读取数据,实在搞不懂哎。谢了。