CASToR
2.0
Tomographic Reconstruction (PET/SPECT/CT)
|
Portable read-only memory mapping (Windows and Linux) More...
#include <oMemoryMapped.hh>
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... | |
oMemoryMapped & | operator= (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... | |
Portable read-only memory mapping (Windows and Linux)
Filesize limited by size_t, usually 2^32 or 2^64
Definition at line 52 of file oMemoryMapped.hh.
|
private |
define handle
Definition at line 124 of file oMemoryMapped.hh.
tweak performance
Enumerator | |
---|---|
Normal |
good overall performance |
SequentialScan |
read file only once with few seeks |
RandomAccess |
jump around |
Definition at line 56 of file oMemoryMapped.hh.
how much should be mappend
Enumerator | |
---|---|
WholeFile |
everything ... be careful when file is larger than memory |
Definition at line 64 of file oMemoryMapped.hh.
oMemoryMapped::oMemoryMapped | ( | ) |
do nothing, must use open()
Definition at line 70 of file oMemoryMapped.cc.
oMemoryMapped::oMemoryMapped | ( | const std::string & | filename, |
size_t | mappedBytes = WholeFile , |
||
CacheHint | hint = Normal |
||
) |
open file, mappedBytes = 0 maps the whole file
Definition at line 89 of file oMemoryMapped.cc.
oMemoryMapped::~oMemoryMapped | ( | ) |
close file (see close() )
Definition at line 109 of file oMemoryMapped.cc.
|
private |
don't copy object
unsigned char oMemoryMapped::at | ( | size_t | offset | ) | const |
access position, including range checking
Definition at line 279 of file oMemoryMapped.cc.
void oMemoryMapped::Close | ( | ) |
close file
Definition at line 227 of file oMemoryMapped.cc.
const unsigned char * oMemoryMapped::GetData | ( | ) | const |
raw access
Definition at line 296 of file oMemoryMapped.cc.
|
staticprivate |
get OS page size (for remap)
Definition at line 439 of file oMemoryMapped.cc.
bool oMemoryMapped::IsValid | ( | ) | const |
true, if file successfully opened
Definition at line 307 of file oMemoryMapped.cc.
size_t oMemoryMapped::mappedSize | ( | ) | const |
get number of actually mapped bytes
Definition at line 329 of file oMemoryMapped.cc.
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 120 of file oMemoryMapped.cc.
|
private |
don't copy object
unsigned char oMemoryMapped::operator[] | ( | size_t | offset | ) | const |
access position, no range checking (faster)
Definition at line 268 of file oMemoryMapped.cc.
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 340 of file oMemoryMapped.cc.
uint64_t oMemoryMapped::size | ( | ) | const |
get file size
Definition at line 318 of file oMemoryMapped.cc.
|
private |
file handle
Definition at line 128 of file oMemoryMapped.hh.
|
private |
file name
Definition at line 110 of file oMemoryMapped.hh.
|
private |
file size
Definition at line 112 of file oMemoryMapped.hh.
|
private |
caching strategy
Definition at line 114 of file oMemoryMapped.hh.
|
private |
mapped size
Definition at line 116 of file oMemoryMapped.hh.
|
private |
pointer to the file contents mapped into memory
Definition at line 130 of file oMemoryMapped.hh.