NebulaStream  0.6.213
NebulaStream is a data and application management framework for the internet of things
MMapCircularBuffer Class Reference

#include <MMapCircularBuffer.hpp>

Public Member Functions

 MMapCircularBuffer (size_t capacity)
 
 ~MMapCircularBuffer ()
 
reader read ()
 
writer write ()
 
size_t size () const
 
size_t capacity () const
 
bool full () const
 
bool empty () const
 

Detailed Description

A CircularBuffer which efficiently allows a writer to append data to the buffer which a reader can consume from the Buffer, after the writer commits its changes, during destruction. This variant exploits virtual mapped memory to create the illusion of a continuous ring of memory. The API exposes a writer, which reserves memory for writing and commits written memory using RAII. The reader allows a consumer to peek into the data, before consuming it.

This buffer is not thread safe! More over it is not allowed to have a reader and a writer at the same time.

Constructor & Destructor Documentation

◆ MMapCircularBuffer()

MMapCircularBuffer::MMapCircularBuffer ( size_t  capacity)
explicit

We create a anomynous memory segement, by creating an inmemory File, resizing it to the capacity. The memory segment is mapped into the processes address space twice. That way there exists now two distinct memory addresses that refer to the same memory. A write to address 0 will be equivalent to a write to address capacity. This allows to create the illusion of a ring in memory. Reads and writes that would previously need to account for a wrap around can now be contigous. This illusion is maintained by wrapping the read and write index during reads.

References data, and NES_ASSERT.

◆ ~MMapCircularBuffer()

MMapCircularBuffer::~MMapCircularBuffer ( )

References data.

Member Function Documentation

◆ capacity()

size_t MMapCircularBuffer::capacity ( ) const

Gets the total capacity of the buffer. Capacity is always a multiple of the getpagesize().

Returns
capacity in bytes

Referenced by NES::TEST_F().

Here is the caller graph for this function:

◆ empty()

bool MMapCircularBuffer::empty ( ) const

References size().

Referenced by NES::TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ full()

bool MMapCircularBuffer::full ( ) const

References size().

Referenced by NES::TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read()

MMapCircularBuffer::reader MMapCircularBuffer::read ( )

Returns a view of the readable memory. Calling consume will consume the memory once the destructor of the reader is called.

Returns
reader

References data, NES_ASSERT, NES_TRACE, size(), and SPAN_TYPE.

Referenced by NES::TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

size_t MMapCircularBuffer::size ( ) const

Gets the current size of the buffer

Returns
size in bytes

Referenced by empty(), full(), read(), NES::TEST_F(), and write().

Here is the caller graph for this function:

◆ write()

MMapCircularBuffer::writer MMapCircularBuffer::write ( )

Returns a view of the writeable memory. Calling consume will mark the memory as used once the destructor of the writer is called.

Returns
writer

References data, NES_ASSERT, NES_TRACE, size(), and SPAN_TYPE.

Referenced by NES::TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

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