ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
MappedRegion Class Reference

#include "MappedRegion.h"

Public Member Functions

 MappedRegion ()=default
 MappedRegion (const MappedRegion &)=delete
MappedRegionoperator= (const MappedRegion &)=delete
std::size_t openFile (const char *filename, bool read_only)
 Open (creating if absent) the backing file.
void resizeFile (std::size_t length)
 Set the backing file's size.
void map (std::size_t length)
 Establish the initial region of length bytes over the file.
void remap (std::size_t new_length)
 Grow the region to new_length, preserving existing content.
void sync ()
 Flush the region to the backing file (no-op when read-only).
void close ()
 Write back (if writable) and release the region and file.
void * base () const
std::size_t length () const

Private Attributes

int fd_ = -1
 Backing file descriptor.
void * base_ = nullptr
 Base of the mapped region / heap buffer.
std::size_t length_ = 0
 Current region length in bytes.
bool read_only_ = false
 Opened read-only (no write-back).

Detailed Description

Definition at line 41 of file MappedRegion.h.

Constructor & Destructor Documentation

◆ MappedRegion() [1/2]

MappedRegion::MappedRegion ( )
default
Here is the caller graph for this function:

◆ MappedRegion() [2/2]

MappedRegion::MappedRegion ( const MappedRegion & )
delete
Here is the call graph for this function:

Member Function Documentation

◆ base()

void * MappedRegion::base ( ) const
inline

Definition at line 156 of file MappedRegion.h.

◆ close()

void MappedRegion::close ( )
inline

Write back (if writable) and release the region and file.

Definition at line 140 of file MappedRegion.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ length()

std::size_t MappedRegion::length ( ) const
inline

Definition at line 157 of file MappedRegion.h.

Here is the caller graph for this function:

◆ map()

void MappedRegion::map ( std::size_t length)
inline

Establish the initial region of length bytes over the file.

Definition at line 86 of file MappedRegion.h.

Here is the call graph for this function:

◆ openFile()

std::size_t MappedRegion::openFile ( const char * filename,
bool read_only )
inline

Open (creating if absent) the backing file.

Returns
The file's current size in bytes (0 if newly created).

Definition at line 56 of file MappedRegion.h.

◆ operator=()

MappedRegion & MappedRegion::operator= ( const MappedRegion & )
delete
Here is the call graph for this function:

◆ remap()

void MappedRegion::remap ( std::size_t new_length)
inline

Grow the region to new_length, preserving existing content.

Definition at line 106 of file MappedRegion.h.

Here is the call graph for this function:

◆ resizeFile()

void MappedRegion::resizeFile ( std::size_t length)
inline

Set the backing file's size.

The shared-mmap backend must pre-size the file (mmap maps file-backed pages). The heap-buffer backend does not: it allocates the buffer and sync() extends the file with pwrite. Crucially, leaving the file unsized until the first sync() means a fresh file that is never synced (e.g. a backend that aborts before write-back) stays empty on disk and is re-initialised cleanly on reopen, rather than persisting as a full-size, never-written file whose zero header fails magic validation.

Definition at line 76 of file MappedRegion.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sync()

void MappedRegion::sync ( )
inline

Flush the region to the backing file (no-op when read-only).

Definition at line 128 of file MappedRegion.h.

Here is the caller graph for this function:

Member Data Documentation

◆ base_

void* MappedRegion::base_ = nullptr
private

Base of the mapped region / heap buffer.

Definition at line 43 of file MappedRegion.h.

◆ fd_

int MappedRegion::fd_ = -1
private

Backing file descriptor.

Definition at line 42 of file MappedRegion.h.

◆ length_

std::size_t MappedRegion::length_ = 0
private

Current region length in bytes.

Definition at line 44 of file MappedRegion.h.

◆ read_only_

bool MappedRegion::read_only_ = false
private

Opened read-only (no write-back).

Definition at line 45 of file MappedRegion.h.


The documentation for this class was generated from the following file: