CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
oMemoryMapped Class Reference

Portable read-only memory mapping (Windows and Linux) More...

#include <oMemoryMapped.hh>

Collaboration diagram for oMemoryMapped:
Collaboration graph

Public Types

enum  CacheHint { Normal, SequentialScan, RandomAccess }
 tweak performance More...
 
enum  MapRange { WholeFile = 0 }
 how much should be mappend More...
 

Public Member Functions

 oMemoryMapped ()
 do nothing, must use open() More...
 
 oMemoryMapped (const std::string &filename, size_t mappedBytes=WholeFile, CacheHint hint=Normal)
 open file, mappedBytes = 0 maps the whole file More...
 
 ~oMemoryMapped ()
 close file (see close() ) More...
 
int Open (const std::string &filename, size_t mappedBytes=WholeFile, CacheHint hint=Normal)
 open file, mappedBytes = 0 maps the whole file More...
 
void Close ()
 close file More...
 
unsigned char operator[] (size_t offset) const
 access position, no range checking (faster) More...
 
unsigned char at (size_t offset) const
 access position, including range checking More...
 
const unsigned char * GetData () const
 raw access More...
 
bool IsValid () const
 true, if file successfully opened More...
 
uint64_t size () const
 get file size More...
 
size_t mappedSize () const
 get number of actually mapped bytes More...
 
int Remap (uint64_t offset, size_t mappedBytes)
 replace mapping by a new one of the same file, offset MUST be a multiple of the page size More...
 

Private Types

typedef int FileHandle
 define handle More...
 

Private Member Functions

 oMemoryMapped (const oMemoryMapped &)
 don't copy object More...
 
oMemoryMappedoperator= (const oMemoryMapped &)
 don't copy object More...
 

Static Private Member Functions

static int GetPageSize ()
 get OS page size (for remap) More...
 

Private Attributes

std::string _filename
 file name More...
 
uint64_t _filesize
 file size More...
 
CacheHint _hint
 caching strategy More...
 
size_t _mappedBytes
 mapped size More...
 
FileHandle _file
 file handle More...
 
void * _mappedView
 pointer to the file contents mapped into memory More...
 

Detailed Description

Portable read-only memory mapping (Windows and Linux)

Filesize limited by size_t, usually 2^32 or 2^64

Definition at line 51 of file oMemoryMapped.hh.

Member Typedef Documentation

◆ FileHandle

typedef int oMemoryMapped::FileHandle
private

define handle

Definition at line 123 of file oMemoryMapped.hh.

Member Enumeration Documentation

◆ CacheHint

tweak performance

Enumerator
Normal 

good overall performance

SequentialScan 

read file only once with few seeks

RandomAccess 

jump around

Definition at line 55 of file oMemoryMapped.hh.

◆ MapRange

how much should be mappend

Enumerator
WholeFile 

everything ... be careful when file is larger than memory

Definition at line 63 of file oMemoryMapped.hh.

Constructor & Destructor Documentation

◆ oMemoryMapped() [1/3]

oMemoryMapped::oMemoryMapped ( )

do nothing, must use open()

Definition at line 69 of file oMemoryMapped.cc.

◆ oMemoryMapped() [2/3]

oMemoryMapped::oMemoryMapped ( const std::string &  filename,
size_t  mappedBytes = WholeFile,
CacheHint  hint = Normal 
)

open file, mappedBytes = 0 maps the whole file

Definition at line 88 of file oMemoryMapped.cc.

Here is the call graph for this function:

◆ ~oMemoryMapped()

oMemoryMapped::~oMemoryMapped ( )

close file (see close() )

Definition at line 108 of file oMemoryMapped.cc.

Here is the call graph for this function:

◆ oMemoryMapped() [3/3]

oMemoryMapped::oMemoryMapped ( const oMemoryMapped )
private

don't copy object

Member Function Documentation

◆ at()

unsigned char oMemoryMapped::at ( size_t  offset) const

access position, including range checking

Definition at line 280 of file oMemoryMapped.cc.

Here is the call graph for this function:

◆ Close()

void oMemoryMapped::Close ( )

close file

Definition at line 228 of file oMemoryMapped.cc.

Here is the caller graph for this function:

◆ GetData()

const unsigned char * oMemoryMapped::GetData ( ) const

raw access

Definition at line 297 of file oMemoryMapped.cc.

Here is the caller graph for this function:

◆ GetPageSize()

int oMemoryMapped::GetPageSize ( )
staticprivate

get OS page size (for remap)

Definition at line 442 of file oMemoryMapped.cc.

◆ IsValid()

bool oMemoryMapped::IsValid ( ) const

true, if file successfully opened

Definition at line 308 of file oMemoryMapped.cc.

Here is the caller graph for this function:

◆ mappedSize()

size_t oMemoryMapped::mappedSize ( ) const

get number of actually mapped bytes

Definition at line 330 of file oMemoryMapped.cc.

◆ Open()

int oMemoryMapped::Open ( const std::string &  filename,
size_t  mappedBytes = WholeFile,
CacheHint  hint = Normal 
)

open file, mappedBytes = 0 maps the whole file

open file

Definition at line 119 of file oMemoryMapped.cc.

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

◆ operator=()

oMemoryMapped& oMemoryMapped::operator= ( const oMemoryMapped )
private

don't copy object

◆ operator[]()

unsigned char oMemoryMapped::operator[] ( size_t  offset) const

access position, no range checking (faster)

Definition at line 269 of file oMemoryMapped.cc.

Here is the caller graph for this function:

◆ Remap()

int oMemoryMapped::Remap ( uint64_t  offset,
size_t  mappedBytes 
)

replace mapping by a new one of the same file, offset MUST be a multiple of the page size

Definition at line 341 of file oMemoryMapped.cc.

Here is the caller graph for this function:

◆ size()

uint64_t oMemoryMapped::size ( ) const

get file size

Definition at line 319 of file oMemoryMapped.cc.

Member Data Documentation

◆ _file

FileHandle oMemoryMapped::_file
private

file handle

Definition at line 127 of file oMemoryMapped.hh.

◆ _filename

std::string oMemoryMapped::_filename
private

file name

Definition at line 109 of file oMemoryMapped.hh.

◆ _filesize

uint64_t oMemoryMapped::_filesize
private

file size

Definition at line 111 of file oMemoryMapped.hh.

◆ _hint

CacheHint oMemoryMapped::_hint
private

caching strategy

Definition at line 113 of file oMemoryMapped.hh.

◆ _mappedBytes

size_t oMemoryMapped::_mappedBytes
private

mapped size

Definition at line 115 of file oMemoryMapped.hh.

◆ _mappedView

void* oMemoryMapped::_mappedView
private

pointer to the file contents mapped into memory

Definition at line 129 of file oMemoryMapped.hh.


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