Append-only, mmap-backed vector of elements of type T.
More...
#include "MMappedVector.h"
|
| struct | data_t |
| | On-disk layout stored at the start of the backing file. More...
|
| |
|
| | MMappedVector (const char *filename, bool read_only) |
| | Open (or create) the mmap-backed vector.
|
| |
| | ~MMappedVector () |
| | Sync and unmap the file.
|
| |
| const T & | operator[] (unsigned long k) const |
| | Read-only element access by index.
|
| |
| T & | operator[] (unsigned long k) |
| | Read-write element access by index.
|
| |
| void | add (const T &value) |
| | Append an element to the end of the vector.
|
| |
| unsigned long | nbElements () const |
| | Return the number of elements currently stored.
|
| |
| void | sync () |
| | Flush dirty pages to the backing file with msync().
|
| |
|
| void | mmap (size_t length, bool read_only) |
| | Map length bytes from the backing file.
|
| |
| void | grow () |
| | Double the backing file and remap.
|
| |
| void | set (pg_uuid_t u, unsigned long i) |
| | Unused overload kept for interface compatibility.
|
| |
|
| int | fd |
| | File descriptor of the backing mmap file.
|
| |
| data_t * | data |
| | Pointer to the memory-mapped data header.
|
| |
|
| static constexpr unsigned | STARTING_CAPACITY =(1u << 16) |
| | Initial number of element slots allocated.
|
| |
template<typename T>
class MMappedVector< T >
Append-only, mmap-backed vector of elements of type T.
- Template Parameters
-
| T | The element type. Must be trivially copyable. |
Definition at line 36 of file MMappedVector.h.
◆ MMappedVector()
Open (or create) the mmap-backed vector.
- Parameters
-
| filename | Path to the backing file (created with STARTING_CAPACITY slots if absent). |
| read_only | If true, map the file read-only. |
Definition at line 40 of file MMappedVector.hpp.
◆ ~MMappedVector()
◆ add()
Append an element to the end of the vector.
Grows the backing file if the current capacity is exhausted.
- Parameters
-
Definition at line 115 of file MMappedVector.hpp.
◆ grow()
◆ mmap()
Map length bytes from the backing file.
- Parameters
-
| length | Number of bytes to map. |
| read_only | If true, map read-only. |
Definition at line 67 of file MMappedVector.hpp.
◆ nbElements()
Return the number of elements currently stored.
- Returns
- Element count.
Definition at line 108 of file MMappedVector.h.
◆ operator[]() [1/2]
Read-write element access by index.
- Parameters
-
| k | Zero-based element index. |
- Returns
- Reference to element
k.
Definition at line 109 of file MMappedVector.hpp.
◆ operator[]() [2/2]
template<typename T >
| const T & MMappedVector< T >::operator[] |
( |
unsigned long |
k | ) |
const |
|
inline |
Read-only element access by index.
- Parameters
-
| k | Zero-based element index. |
- Returns
- Const reference to element
k.
Definition at line 103 of file MMappedVector.hpp.
◆ set()
Unused overload kept for interface compatibility.
- Parameters
-
| u | Ignored UUID parameter. |
| i | Ignored integer parameter. |
◆ sync()
Flush dirty pages to the backing file with msync().
Definition at line 124 of file MMappedVector.hpp.
◆ data
Pointer to the memory-mapped data header.
Definition at line 49 of file MMappedVector.h.
◆ fd
File descriptor of the backing mmap file.
Definition at line 48 of file MMappedVector.h.
◆ STARTING_CAPACITY
template<typename T >
| constexpr unsigned MMappedVector< T >::STARTING_CAPACITY =(1u << 16) |
|
staticconstexprprivate |
Initial number of element slots allocated.
Definition at line 52 of file MMappedVector.h.
The documentation for this class was generated from the following files: