GBTOlib: library for evaluation of molecular integrals in mixed Gaussian / B-spline basis 111
Loading...
Searching...
No Matches
file_mapping.c File Reference
#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>
Include dependency graph for file_mapping.c:

Functions

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.

Function Documentation

◆ 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]filenamePath to the file to map or a prefix for automatically generated name.
[in]offsetByte position in file to begin the mapping.
[in]lengthByte length of the mapped window (buffer).
[out]addrInternal address that needs to be passed to unmap_file_window to cancel the mapping.
[out]ptrPointer to memory where the mapped data begin.
[in]read_writeIf set to 1, allow write access to the mapped memory.
[in]unique_nameIf set to 1, interpret filename only as a prefix, and supplement it with a unique ending.
[in]create_newIf 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]addrInternal address obtained from map_file_window.
[in]lengthLength of the mapped data segment.