#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
|
| void | map_file_window (const char *filename, size_t offset, size_t length, void **addr, void **ptr, int read_write, int unique_name, int create_new) |
| | Map data segment from file.
|
| void | unmap_file_window (void *addr, size_t length) |
| | Cancel file mapping.
|
◆ map_file_window()
| void map_file_window |
( |
const char * | filename, |
|
|
size_t | offset, |
|
|
size_t | length, |
|
|
void ** | addr, |
|
|
void ** | ptr, |
|
|
int | read_write, |
|
|
int | unique_name, |
|
|
int | create_new ) |
Map data segment from file.
- Authors
- J Benda
- Date
- 2020 - 2025
Assigns a virtual memory range to a contiguous data segment within a disk file, which can be used as any other memory buffer. The file need not exist; if create_new is set to 1, it will be created first, sufficiently large to hold the requested memory range. The file name can be left partially unspecified (by setting unique_name to 1) to allow the operating system to generate a unique file path with the prefix given by filename. Such automatically created files will be deleted once the mapping is canceled (or the program ends).
- Parameters
-
| [in] | filename | Path to the file to map or a prefix for automatically generated name. |
| [in] | offset | Byte position in file to begin the mapping. |
| [in] | length | Byte length of the mapped window (buffer). |
| [out] | addr | Internal address that needs to be passed to unmap_file_window to cancel the mapping. |
| [out] | ptr | Pointer to memory where the mapped data begin. |
| [in] | read_write | If set to 1, allow write access to the mapped memory. |
| [in] | unique_name | If set to 1, interpret filename only as a prefix, and supplement it with a unique ending. |
| [in] | create_new | If set to 1, create a new file instead of mapping an existing one. |
◆ unmap_file_window()
| void unmap_file_window |
( |
void * | addr, |
|
|
size_t | length ) |
Cancel file mapping.
- Authors
- J Benda
- Date
- 2020 - 2021
Release memory mapping, allowing e.g. final deletion of the file.
- Parameters
-
| [in] | addr | Internal address obtained from map_file_window. |
| [in] | length | Length of the mapped data segment. |