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);
    uint Read(T[] destination, uint offset, uint maxCount);
    uint Peek(T[] destination, uint offset, uint maxCount);
    uint Advance(uint count);
    void Clear();
};

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.

uint Read(T[] destination, uint offset, uint maxCount)

Reads data into a caller supplied buffer. Does not allocate.

Parameters:

destination

The buffer to read into.

offset

Where in destination to start writing.

maxCount

The max number of items to read.

Returns:

The number of items read.

uint Peek(T[] destination, uint offset, uint maxCount)

Copies data into a caller supplied buffer without advancing the read cursor. Does not allocate.

Parameters:

destination

The buffer to copy into.

offset

Where in destination to start writing.

maxCount

The max number of items to copy.

Returns:

The number of items copied.

uint Advance(uint count)

Advances the read cursor, discarding the items it passes over.

Parameters:

count

How many items to discard.

Returns:

The number of items actually discarded.

void Clear()

Empties the buffer.