Пример отображаемых в памяти файлов

Советы » Файлы » Пример отображаемых в памяти файлов

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. }

Другое по теме:

Категории

Статьи

Советы

Copyright © 2022 - All Rights Reserved - www.delphirus.com