libdballe
9.11
|
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. More... | |
unsigned | membuf_last = 0 |
Number of items in membuf. | |
const T * | readbuf = (const T*)MAP_FAILED |
Memory area used for reading. More... | |
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. | |
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.
|
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().
|
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().