12#include <boost/multi_index/hashed_index.hpp>
13#include <boost/multi_index/mem_fun.hpp>
14#include <boost/multi_index/ordered_index.hpp>
15#include <boost/multi_index/sequenced_index.hpp>
16#include <boost/multi_index_container.hpp>
48 using freeSpace_t = boost::multi_index::multi_index_container<
49 FreeBlock, boost::multi_index::indexed_by<
50 boost::multi_index::ordered_non_unique<
51 ::boost::multi_index::const_mem_fun<FreeBlock, uint64_t, &FreeBlock::getFilePosition>>,
52 boost::multi_index::ordered_non_unique<
53 ::boost::multi_index::const_mem_fun<FreeBlock, uint64_t, &FreeBlock::getSize>>>>;
69 void freeBlock(uint64_t
const pos, uint64_t
const size);
70 void defragFreeBlocks();
73 uint64_t allocate(uint64_t
const newSize);
74 uint64_t relocate(uint64_t
const oldPos, uint64_t
const oldSize,
const uint64_t newSize);
77 void getFreeSpaceVector(std::vector<uint64_t> &free)
const;
78 void setFreeSpaceVector(std::vector<uint64_t> &free);
79 std::string getMemoryStr()
const;
86 if (buffer > std::numeric_limits<size_t>::max() / 2)
87 throw std::runtime_error(
" Can not aloocate memory for that many events "
88 "on given architecture ");
90 m_writeBufferSize =
static_cast<size_t>(buffer);
116 inline void writeOldObjects();
Buffer objects that need to be written out to disk so as to optimize writing operations.
DiskBuffer(const DiskBuffer &)=delete
std::mutex m_freeMutex
Mutex for modifying the free space list.
uint64_t getWriteBufferSize() const
freeSpace_t & getFreeSpaceMap()
uint64_t getFileLength() const
std::list< ISaveable * > m_toWriteBuffer
A forward list for the buffer of "toWrite" objects.
uint64_t m_fileLength
Length of the file. This is where new blocks that don't fit get placed.
size_t m_writeBufferUsed
Total amount of memory in the "toWrite" buffer.
boost::multi_index::multi_index_container< FreeBlock, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< ::boost::multi_index::const_mem_fun< FreeBlock, uint64_t, &FreeBlock::getFilePosition > >, boost::multi_index::ordered_non_unique< ::boost::multi_index::const_mem_fun< FreeBlock, uint64_t, &FreeBlock::getSize > > > > freeSpace_t
A map for the list of free space blocks in the file.
size_t m_nObjectsToWrite
number of objects stored in to write buffer list
void setFileLength(const uint64_t length) const
Set the length of the file that this MRU writes to.
uint64_t getWriteBufferUsed() const
freeSpace_bySize_t & m_free_bySize
Index into m_free, but indexed by block size.
size_t m_writeBufferSize
Do we use the write buffer? Always now.
void setWriteBufferSize(uint64_t buffer)
Set the size of the to-write buffer, in number of events.
freeSpace_t::nth_index< 1 >::type freeSpace_bySize_t
A way to index the free space by their size.
std::mutex m_mutex
Mutex for modifying the the toWrite buffer.
DiskBuffer & operator=(const DiskBuffer &)=delete
virtual ~DiskBuffer()=default
freeSpace_t m_free
Map of the free blocks in the file.
FreeBlock: a simple class that holds the position and size of block of free space in a file.
An interface for objects that can be cached or saved to disk.
Helper class which provides the Collimation Length for SANS instruments.