1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| var file_, map : dword;
buf: pointer;
begin
file_ := CreateFile('c:\file1.txt', GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
if file_ <> INVALID_HANDLE_VALUE then
try
map := CreateFileMapping(file_, nil, PAGE_READWRITE, 0, 0, nil);
if map <> 0 then
try
buf := MapViewOfFile(map, FILE_MAP_ALL_ACCESS, 0, 0, 0);
if buf <> nil then
try
// now here you have your file1.txt in memory
// beginning at pointer "buf"
finally UnmapViewOfFile(buf) end;
finally CloseHandle(map) end;
finally CloseHandle(file_) end;
end;
{
This logic maps your complete file into memory. It's not COPIED into
memory, only MAPPED. In the moment where you access the single bytes
of the file in memory, Windows internally reads the file for you in the
fastest possible way. } |
Partager