Procedure mapmemoryfilecopy (sourcefilename, targetfilename: string );
Const
Buffersize = 1024*1024*64;
VaR
Sourcehandle: thandle; // source file handle
Targethandle: thandle; // target file handle
Fsize: Cardinal; // the file size is 32 characters low.
Highsize: Cardinal; // 32-bit File Size
Totalsize: int64; // file Overview
Smaphandle: thandle; // Source File Memory ing handle
Tmaphandle: thandle; // memory ing handle of the target file
Psource: pointer; // Source File Memory ing view Address
PTARGET: pointer; // address of the memory ing view of the target file
Startpos: int64;
Mapsize: Cardinal;
Function makeint64 (high, low: Cardinal): int64;
Begin
Move (pchar (@ high) ^, pchar (longint (@ result) + sizeof (Cardinal) ^,
Sizeof (Cardinal ));
Move (pchar (@ low) ^, pchar (@ result) ^, sizeof (Cardinal ));
End;
Function high32 (Num: int64): Cardinal;
Begin
Move (pchar (longint (@ num) + sizeof (Cardinal) ^, pchar (@ result) ^,
Sizeof (Cardinal ));
End;
Function low32 (Num: int64): Cardinal;
Begin
Move (pchar (@ num) ^, pchar (@ result) ^, sizeof (Cardinal ));
End;
Begin
// Source file
Sourcehandle: = fileopen (sourcefilename, fmopenread );
Fsize: = getfilesize (sourcehandle, @ highsize );
Totalsize: = highsize * 1024*1024*1024*4 + fsize;
Smaphandle: = createfilemapping (sourcehandle, nil, page_readonly,
Highsize, fsize, nil );
Closehandle (sourcehandle );
// Target file
Targethandle: = filecreate (targetfilename );
Tmaphandle: = createfilemapping (targethandle, nil, page_readwrite,
Highsize, fsize, nil );
Closehandle (targethandle );
// Initialize the variable
Startpos: = 0;
Mapsize: = buffersize;
While startpos <totalsize do
Begin
If startpos + buffersize> totalsize then
Mapsize: = totalsize-startpos;
// Create a ing view. The obtained psource and pTARGET pointers can be used for memory operations like normal pointers.
Psource: = mapviewoffile (smaphandle, file_map_read,
High32 (startpos), low32 (startpos), mapsize );
PTARGET: = mapviewoffile (tmaphandle, file_map_read or
File_map_write,
High32 (startpos), low32 (startpos), mapsize );
// Copy
Move (pbyte (psource) ^, pbyte (pTARGET) ^, mapsize );
Startpos: = startpos + mapsize;
// Cancel the memory ing View
Unmapviewoffile (psource );
Unmapviewoffile (pTARGET );
End;
// Close file ing
Closehandle (smaphandle );
Closehandle (tmaphandle );
End;
VaR
T: longint;
Begin
T: = gettickcount ();
Mapmemoryfilecopy ('C:/newdl. VCT ', 'c:/11. VCT ');
T: = gettickcount ()-T;
Showmessage (inttostr (t ));
End;