libdballe 9.6
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dballe::Structbuf< T, bufsize > Class Template Reference

Buffer of simple structures that becomes file backed if it grows beyond a certain size. More...

#include <structbuf.h>

Public Member Functions

size_t size () const
 Get the number of structures that have been added to the buffer so far.
 
bool is_file_backed () const
 Return true if the buffer has become file-backed.
 
void append (const T &val)
 Append an item to the buffer.
 
void ready_to_read ()
 Stop appending and get ready to read back the data.
 
const T & operator[] (size_t idx) const
 Read back an item.
 

Protected Member Functions

void write_to_file ()
 

Protected Attributes

T * membuf = nullptr
 In-memory buffer using during appending.
 
unsigned membuf_last = 0
 Number of items in membuf.
 
const T * readbuf = (const T*)MAP_FAILED
 Memory area used for reading.
 
size_t m_count = 0
 Number of items appended so far.
 
int tmpfile_fd = -1
 Unix file descriptor to the temporary file, or -1 if we are memory backed.
 

Detailed Description

template<typename T, int bufsize = 1024>
class dballe::Structbuf< T, bufsize >

Buffer of simple structures that becomes file backed if it grows beyond a certain size.

bufsize is the number of T items that we keep in memory before becoming file-backed.

Member Data Documentation

◆ membuf

template<typename T , int bufsize = 1024>
T* dballe::Structbuf< T, bufsize >::membuf = nullptr
protected

In-memory buffer using during appending.

When it becomes full, it is flushed out to a temporary file.

Referenced by dballe::Structbuf< T, bufsize >::append(), and dballe::Structbuf< T, bufsize >::ready_to_read().

◆ readbuf

template<typename T , int bufsize = 1024>
const T* dballe::Structbuf< T, bufsize >::readbuf = (const T*)MAP_FAILED
protected

Memory area used for reading.

It points to membuf if we are memory-backed, or it is the mmap view of the file if we are file-backed

Referenced by dballe::Structbuf< T, bufsize >::append(), dballe::Structbuf< T, bufsize >::operator[](), and dballe::Structbuf< T, bufsize >::ready_to_read().


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