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>
130 tmpfile_fd = structbuf::make_anonymous_tmpfile();
Buffer of simple structures that becomes file backed if it grows beyond a certain size.
Definition: structbuf.h:46
T * membuf
In-memory buffer using during appending.
Definition: structbuf.h:52
void ready_to_read()
Stop appending and get ready to read back the data.
Definition: structbuf.h:104
unsigned membuf_last
Number of items in membuf.
Definition: structbuf.h:55
const T * readbuf
Memory area used for reading.
Definition: structbuf.h:61
size_t m_count
Number of items appended so far.
Definition: structbuf.h:64
size_t size() const
Get the number of structures that have been added to the buffer so far.
Definition: structbuf.h:87
bool is_file_backed() const
Return true if the buffer has become file-backed.
Definition: structbuf.h:90
void append(const T &val)
Append an item to the buffer.
Definition: structbuf.h:93
int tmpfile_fd
Unix file descriptor to the temporary file, or -1 if we are memory backed.
Definition: structbuf.h:68
const T & operator[](size_t idx) const
Read back an item.
Definition: structbuf.h:121