Code:
function CreateFileMapping(
File: Cardinal; Attributes: Cardinal; Protect: Cardinal;
MaximumSizeHigh: Cardinal; MaximumSizeLow: Cardinal; Name: PAnsiChar): Cardinal;
external '[email protected] stdcall';
function MapViewOfFile(
FileMappingObject: THandle; DesiredAccess: Cardinal; FileOffsetHigh: Cardinal;
FileOffsetLow: Cardinal; NumberOfBytesToMap: Cardinal): PChar;
external '[email protected] stdcall';
What is FileMapping & benefits of FileMapping?
File mapping is a technique that allows you to map the contents of a file into the virtual memory space of a process. This allows you to access the contents of the file as if it were in memory, rather than on disk.
There are several benefits to using file mapping:
• Performance: File mapping can improve the performance of file I/O operations by reducing the number of disk accesses. When you map a file into memory, the operating system can use its virtual memory management mechanisms to cache the contents of the file in memory. This means that subsequent accesses to the file can be satisfied from memory, rather than requiring a disk access.
• Concurrency: File mapping allows multiple processes to access the same file concurrently. When multiple processes map the same file into their virtual memory space, they can all access the contents of the file simultaneously. This can be useful for inter-process communication and data sharing.
• Ease of use: File mapping allows you to access the contents of a file using memory-mapped I/O operations, rather than traditional file I/O operations. This can make it easier to work with files, as you can use pointer arithmetic and other memory-based operations to manipulate the contents of the file.
Overall, file mapping is a powerful technique that can improve the performance and ease-of-use of file I/O operations. It is widely used in many different types of applications and is supported by most modern operating systems.