Developer documentation
Version 3.0.3-105-gd3941f44
MR::File::MMap Class Reference

#include "file/mmap.h"

Inheritance diagram for MR::File::MMap:
MR::File::Entry

Public Member Functions

 MMap (const Entry &entry, bool readwrite=false, bool preload=true, int64_t mapped_size=-1)
 create a new memory-mapping to file in entry More...
 
 ~MMap ()
 
std::string name () const
 
int64_t size () const
 
uint8_t * address ()
 
const uint8_t * address () const
 
bool is_read_write () const
 
bool changed () const
 

Protected Member Functions

void map ()
 
- Protected Member Functions inherited from MR::File::Entry
 Entry (const std::string &fname, int64_t offset=0)
 
 Entry (const Entry &)=default
 
 Entry (Entry &&) noexcept=default
 
Entryoperator= (Entry &&E) noexcept
 

Protected Attributes

int fd
 
uint8_t * addr
 
uint8_t * first
 
int64_t msize
 
time_t mtime
 
bool readwrite
 
- Protected Attributes inherited from MR::File::Entry
std::string name
 
int64_t start
 

Friends

std::ostream & operator<< (std::ostream &stream, const MMap &m)
 

Detailed Description

Definition at line 32 of file mmap.h.

Constructor & Destructor Documentation

◆ MMap()

MR::File::MMap::MMap ( const Entry entry,
bool  readwrite = false,
bool  preload = true,
int64_t  mapped_size = -1 
)

create a new memory-mapping to file in entry

map file in entry at the offset in entry. By default, the file will be mapped read-only. If readwrite is set to true, the file will be accessed with read-write permissions, but the mechanism used depends on whether the file is detected as residing on a local or a networked filesystem, and whether the filesystem is mounted with synchronous IO. If the filesystem is local and asynchronous, the file is memory-mapped as-is with read-write permissions. Otherwise, a write-back RAM buffer is allocated to store the contents of the file, and written back when the constructor is invoked.

By default, if the file is mapped using the delayed write-back mechanism, its contents will be preloaded into the RAM buffer. If the file has just been created, preload should be set to false to prevent this, in which case the contents will set to zero.

By default, the whole file is mapped. If mapped_size is non-zero, then only the region of size mapped_size starting from the byte offset specified in entry will be mapped.

◆ ~MMap()

MR::File::MMap::~MMap ( )

Member Function Documentation

◆ address() [1/2]

uint8_t * MR::File::MMap::address ( )
inline

Definition at line 64 of file mmap.h.

◆ address() [2/2]

const uint8_t * MR::File::MMap::address ( ) const
inline

Definition at line 67 of file mmap.h.

◆ changed()

bool MR::File::MMap::changed ( ) const

◆ is_read_write()

bool MR::File::MMap::is_read_write ( ) const
inline

Definition at line 71 of file mmap.h.

◆ map()

void MR::File::MMap::map ( )
protected

◆ name()

std::string MR::File::MMap::name ( ) const
inline

Definition at line 58 of file mmap.h.

◆ size()

int64_t MR::File::MMap::size ( ) const
inline

Definition at line 61 of file mmap.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  stream,
const MMap m 
)
friend

Definition at line 76 of file mmap.h.

Member Data Documentation

◆ addr

uint8_t* MR::File::MMap::addr
protected

The address in memory where the file has been mapped.

Definition at line 85 of file mmap.h.

◆ fd

int MR::File::MMap::fd
protected

Definition at line 84 of file mmap.h.

◆ first

uint8_t* MR::File::MMap::first
protected

The address in memory to the start of the region of interest.

Definition at line 86 of file mmap.h.

◆ msize

int64_t MR::File::MMap::msize
protected

The size of the file.

Definition at line 87 of file mmap.h.

◆ mtime

time_t MR::File::MMap::mtime
protected

The modification time of the file at the last check.

Definition at line 88 of file mmap.h.

◆ readwrite

bool MR::File::MMap::readwrite
protected

Definition at line 89 of file mmap.h.


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