template class MAGES::Recorder::Utilities::RingBuffer

Overview

A ring buffer template class. More…

template 
class RingBuffer
{
public:
    // properties

    uint ReadCountUnsafe;
    uint WriteCountUnsafe;
    uint ReadCursorUnsafe;
    uint WriteCursorUnsafe;
    int Size;
    uint ReadCount;
    uint WriteCount;

    // methods

    RingBuffer(uint size);
    bool TryWrite(T[] data);
    T[] Read(uint maxCount);
};

Detailed Documentation

A ring buffer template class.

Parameters:

T

The type of data to hold.

Properties

uint ReadCountUnsafe

Gets the number of elements that can be read (unsafe, no lock).

uint WriteCountUnsafe

Gets the number of elements that can be written (unsafe, no lock).

uint ReadCursorUnsafe

Gets the read cursor (unsafe, no lock).

uint WriteCursorUnsafe

Gets the write cursor (unsafe, no lock).

int Size

Gets the size of the ring buffer.

uint ReadCount

Gets the number of elements that can be read.

uint WriteCount

Gets the number of elements that can be written.

Methods

RingBuffer(uint size)

Initializes a new instance of the RingBuffer<T> class.

Parameters:

size

How big the ring buffer should be.

bool TryWrite(T[] data)

Writes data to the ring buffer.

Parameters:

data

The data to write.

Returns:

True only if all the data was written. Otherwise nothing is written and the function returns false.

T[] Read(uint maxCount)

Reads data from the ring buffer.

Parameters:

maxCount

The max number of items to read.

Returns:

An array of read items, if no items could be read, returns null.