![]() |
Scanframe Modular Application 0.1.0
|
This class provides storing of huge amounts of data using file mapping.
Mapping only what is needed into memory.
More...
#include <FileMappedStorage.h>
Classes | |
class | Lock |
Provides easy way to lock a pointer to the memory. More... | |
Public Types | |
typedef uint64_t | size_type |
Type used for sizes of storage. | |
Public Member Functions | |
FileMappedStorage (size_type seg_sz, size_type blk_sz, size_type recycle=0) | |
FileMappedStorage (const FileMappedStorage &) | |
Copy constructor. | |
virtual | ~FileMappedStorage () |
Virtual destructor. | |
bool | reserve (size_type block_count) |
Reserves an amount of blocks and rounds it up to the nearest segment size. | |
void | flush () |
Flushes all data stored by this instance. | |
bool | blockWrite (size_type ofs, size_type sz, const void *src) |
Function that store blocks in several segments when needed. | |
bool | blockRead (size_type ofs, size_type sz, void *dst) const |
Function that store blocks in several segments when needed. | |
size_type | getBlockCount () const |
Gets the amount of blocks reserved. | |
size_type | getSegmentCount () const |
Gets the amount of segments used by this instance. | |
size_type | getSegmentLocks () const |
Gets the accumulation of locks on segments. | |
size_type | getBlockSize () const |
Gets the block size in bytes of this instance. | |
size_type | getSegmentSize () const |
Gets the size of the segments in blocks of this instance. | |
size_type | getSize () const |
FileMappedStorage::size_type | getRecycleCount () const |
Gets the amount of segments being recycled. | |
bool | setRecycleCount (size_type count) |
Sets the recycle segment count. | |
std::ostream & | writeStatus (std::ostream &os) const |
Writes the status to the output stream. | |
Static Public Attributes | |
static constexpr size_t | npos = std::numeric_limits<size_type>::max() |
Unsigned size value indicating not found or no index. | |
This class provides storing of huge amounts of data using file mapping.
Mapping only what is needed into memory.
Typically used for data acquisition using digitisers with a vast stream of data in multiple channels.
In some cases the stored data must be kept together in blocks.
A block is a fixed length array of a certain type (mostly integers).
Blocks need to be atomic to for processing later.
All functions are block size oriented and multithreading safe and allowing data be processed in other threads.
The embedded sf::FileMappedStorage::Lock class provides a segment locking mechanism.
The example code below shows it simple usage.
File mapping is done using a sf::IFileMapper derived class has implementations per OS and also a Qt version.
typedef uint64_t sf::FileMappedStorage::size_type |
Type used for sizes of storage.
sf::FileMappedStorage::FileMappedStorage | ( | size_type | seg_sz, |
size_type | blk_sz, | ||
size_type | recycle = 0 |
||
) |
Initializing constructor.
seg_sz | Sets the segment size of storage in blocks. |
blk_sz | Is in bytes. |
recycle | Is the maximum amount of segments allowed to be used for storing. |
sf::FileMappedStorage::FileMappedStorage | ( | const FileMappedStorage & | ) |
Copy constructor.
|
virtual |
Virtual destructor.
|
inline |
Function that store blocks in several segments when needed.
ofs | offset in blocks |
sz | Size in blocks |
dst | Pointer to destination of data. |
|
inline |
Function that store blocks in several segments when needed.
ofs | offset in blocks |
sz | Size in blocks |
src | Pointer to source of data. |
void sf::FileMappedStorage::flush | ( | ) |
Flushes all data stored by this instance.
After this all segments are no longer and reserve() must be called again.
size_type sf::FileMappedStorage::getBlockCount | ( | ) | const |
size_type sf::FileMappedStorage::getBlockSize | ( | ) | const |
Gets the block size in bytes of this instance.
|
inline |
Gets the amount of segments being recycled.
size_type sf::FileMappedStorage::getSegmentCount | ( | ) | const |
Gets the amount of segments used by this instance.
size_type sf::FileMappedStorage::getSegmentLocks | ( | ) | const |
Gets the accumulation of locks on segments.
size_type sf::FileMappedStorage::getSegmentSize | ( | ) | const |
Gets the size of the segments in blocks of this instance.
size_type sf::FileMappedStorage::getSize | ( | ) | const |
Gets the total amount of bytes handled by this instance. Taking recycling into account.
bool sf::FileMappedStorage::reserve | ( | size_type | block_count | ) |
Reserves an amount of blocks and rounds it up to the nearest segment size.
Shrinking is not possible with this method.
block_count | Amount of blocks to reserve. |
bool sf::FileMappedStorage::setRecycleCount | ( | size_type | count | ) |
Sets the recycle segment count.
count | Amount of segments to recycle. |
std::ostream & sf::FileMappedStorage::writeStatus | ( | std::ostream & | os | ) | const |
Writes the status to the output stream.
|
staticconstexpr |
Unsigned size value indicating not found or no index.