22#ifndef DBALLE_CORE_STRUCTBUF_H
23#define DBALLE_CORE_STRUCTBUF_H
33int make_anonymous_tmpfile();
34void write_buffer(
int fd,
void* buf,
size_t size);
44template <
typename T,
int bufsize = 1024>
class Structbuf
70 Structbuf() :
membuf(new T[bufsize]) {}
93 "writing to a Structbuf that is already being read");
116 "cannot map temporary file contents to memory");
127 tmpfile_fd = structbuf::make_anonymous_tmpfile();
Buffer of simple structures that becomes file backed if it grows beyond a certain size.
Definition structbuf.h:45
T * membuf
In-memory buffer using during appending.
Definition structbuf.h:51
void ready_to_read()
Stop appending and get ready to read back the data.
Definition structbuf.h:101
unsigned membuf_last
Number of items in membuf.
Definition structbuf.h:54
const T * readbuf
Memory area used for reading.
Definition structbuf.h:60
size_t m_count
Number of items appended so far.
Definition structbuf.h:63
size_t size() const
Get the number of structures that have been added to the buffer so far.
Definition structbuf.h:83
bool is_file_backed() const
Return true if the buffer has become file-backed.
Definition structbuf.h:86
void append(const T &val)
Append an item to the buffer.
Definition structbuf.h:89
int tmpfile_fd
Unix file descriptor to the temporary file, or -1 if we are memory backed.
Definition structbuf.h:67
const T & operator[](size_t idx) const
Read back an item.
Definition structbuf.h:121