CZCopyRingBuffer

Name

CZCopyRingBuffer -- Provide zero copy access to low level ring buffers.

Synopsis


#include <CZCopyRingBuffer.h>

class CZCopyRingBuffer
{
public:
    CZCopyRingBuffer(CRingBuffer* pRing);
    
    void* get(size_t nBytes);          // Note blocks until nBytes are there.
    void  done();
};
        

DESCRIPTION

The CRingBuffer class provides simple, byte-stream oriented access to NSCLDAQ ring buffers. Retrieving data from ring buffers using this class, however, results in a copy being performed. If high performance is required, these data copies can be a performance impediment.

CZCopyRingBuffer provides mostly copy free access to data placed in a ring buffer. Copies will only take place if the requested data spans the ring buffer wrap in which case that request will be satisfied by creating a local copy for the data that is contiguous in virtual memory.

METHODS

CZCopyRingBuffer(CRingBuffer* pRing);

Creates a zero copy ring buffer access object given a pointer to an underlying CRingBuffer object. The ring buffer must have been attached as a consumer (CRingBuffer::consumer).

void* get(size_t nBytes);

If necessar blocks until at least nBytes of data are avalable for consumption in the underlying ring. The return pointer is then a pointer nBytes of data. In most cases this pointer will point directly the ring buffer and the data pointed to should be treated as readonly. If the data wrapped, the pointer will point at a copy of the data that is contiguous.

Once the callers is done using the data it should invoke the done method.

void done();

Once the client is done using data returned by get it should call this method. The consumer pointer for the client is then advanced past the data gotten by get.

Failure to invoke done will eventually result in the ring buffer being unable to accept new data from the producer resulting in a backpressure flow control condition.