65 static constexpr size_t npos = std::numeric_limits<size_type>::max();
157 [[nodiscard]]
inline size_type getRecycleCount()
const;
205 [[nodiscard]]
inline bool isLocked()
const;
212 [[nodiscard]]
inline size_type getSize()
const;
219 [[nodiscard]]
inline void* lockMemory();
226 [[nodiscard]]
inline const void* lockMemory()
const;
231 inline void unlockMemory()
const;
254 Segment(Segment&) =
delete;
260 Segment& operator=(Segment&) =
delete;
272 void doUnlockMemory();
286 char* _dataPtr{
nullptr};
290 IFileMapper& _fileMapper;
292 friend class FileMappedStorage;
313 Thread::id_type _threadId{0};
317 size_type _blockSize{0};
321 size_type _segmentSize{0};
325 int _referenceCount{0};
329 TVector<Segment*> _segmentList;
337 typedef Mutex::Lock MtLock;
343 Reference* _reference{
nullptr};
384 [[nodiscard]]
bool isAcquired()
const;
390 explicit operator bool()
const;
406 template<
typename T =
void*>
409 return static_cast<T*
>(data(blk_ofs));
433 Segment* _segment{
nullptr};
437 void* _data{
nullptr};
444 bool cacheSegment(size_type idx);
449 void uncacheSegment(size_type idx);
455 size_type _cachedSegmentIndex{npos};
459 size_type _segmentRecycleCount{0};
463 static Mutex _staticSync;
471inline bool FileMappedStorage::Segment::isLocked()
const
473 return (_lockCount > 0);
476inline void* FileMappedStorage::Segment::lockMemory()
482inline const void* FileMappedStorage::Segment::lockMemory()
const
484 const_cast<Segment*
>(
this)->doLockMemory();
485 return const_cast<Segment*
>(
this)->_dataPtr;
488inline void FileMappedStorage::Segment::unlockMemory()
const
490 const_cast<Segment*
>(
this)->doUnlockMemory();
495 return blockReadWrite(
false, ofs, sz, (
void*) src);
505 return _segmentRecycleCount;
510 , _blockSize(ds.getBlockSize())
528 return _data !=
nullptr;
531inline FileMappedStorage::Lock::operator bool()
const
Provides easy way to lock a pointer to the memory.
Definition FileMappedStorage.h:350
~Lock()
Destructor.
Definition FileMappedStorage.h:521
Lock(FileMappedStorage &ds)
Constructor.
Definition FileMappedStorage.h:508
bool isAcquired() const
Gets the segment acquired status.
Definition FileMappedStorage.h:526
void * data(size_type blk_ofs)
Returns pointer to .
T * ptr(size_type blk_ofs)
Definition FileMappedStorage.h:407
void release()
Unlocks memory locked by the segment.
bool acquire(size_type seg_idx)
Tries to lock the segment index of the data store and returns true when successful.
This class provides storing of huge amounts of data using file mapping. Mapping only what is needed ...
Definition FileMappedStorage.h:55
FileMappedStorage(const FileMappedStorage &)
Copy constructor.
bool reserve(size_type block_count)
Reserves an amount of blocks and rounds it up to the nearest segment size.
size_type getSegmentLocks() const
Gets the accumulation of locks on segments.
virtual ~FileMappedStorage()
Virtual destructor.
bool blockRead(size_type ofs, size_type sz, void *dst) const
Function that store blocks in several segments when needed.
Definition FileMappedStorage.h:498
std::ostream & writeStatus(std::ostream &os) const
Writes the status to the output stream.
FileMappedStorage(size_type seg_sz, size_type blk_sz, size_type recycle=0)
bool blockWrite(size_type ofs, size_type sz, const void *src)
Function that store blocks in several segments when needed.
Definition FileMappedStorage.h:493
size_type getBlockCount() const
Gets the amount of blocks reserved.
uint64_t size_type
Type used for sizes of storage.
Definition FileMappedStorage.h:60
void flush()
Flushes all data stored by this instance.
bool setRecycleCount(size_type count)
Sets the recycle segment count.
size_type getSegmentCount() const
Gets the amount of segments used by this instance.
size_type getBlockSize() const
Gets the block size in bytes of this instance.
size_type getRecycleCount() const
Gets the amount of segments being recycled.
Definition FileMappedStorage.h:503
size_type getSize() const
size_type getSegmentSize() const
Gets the size of the segments in blocks of this instance.
#define _GII_CLASS
Definition gii/global.h:38
Definition Application.h:10