NSCL DDAS  12.1-001
Support for XIA DDAS at FRIB
Public Member Functions | Public Attributes | List of all members
DDASReadout::ReferenceCountedBuffer Struct Reference

A reference-counted buffer with dynamic storage. More...

#include <ReferenceCountedBuffer.h>

Public Member Functions

 ReferenceCountedBuffer (size_t initialSize=0)
 Construct the buffer. More...
 
virtual ~ReferenceCountedBuffer ()
 Destructor. More...
 
void reference ()
 Add a reference to the storage. More...
 
void dereference ()
 Remove a reference to the storage. More...
 
bool isReferenced ()
 Are there references to the object? More...
 
void resize (size_t newSize)
 Resize the storage. More...
 
 operator uint8_t * ()
 
 operator uint16_t * ()
 
 operator uint32_t * ()
 

Public Attributes

size_t s_size
 Number of bytes of data. More...
 
size_t s_references
 Number of references. More...
 
void * s_pData
 Data pointer. More...
 

Detailed Description

A reference-counted buffer with dynamic storage.

The idea is that rather than doing data movement, pointers can be registered with the buffer and unregistered. The buffer can then be queried to determine if it can be released, or put in a free list.

One feature of this buffer is that, if there are not references, it can be resized. Since resizing is only legal if there are no references, the contents of the buffer are not preserved across a resize.

The intended use for this data structure is to provide support for zero copy operations in the DDAS Readout program. The idea is that a block of data can be read from a digitizer into one of these and then pointers to each hit created rather than performing copies into other data structures.

Constructor & Destructor Documentation

◆ ReferenceCountedBuffer()

DDASReadout::ReferenceCountedBuffer::ReferenceCountedBuffer ( size_t  initialSize = 0)

Construct the buffer.

Parameters
initialSizeInitial size in bytes allocated to the buffer (default = 0).
Exceptions
std::bad_allocBuffer malloc fails for initialSize > 0.

If initailSize is zero (the default) no storage is allocated and the user must do a resize at some point to get storage.

◆ ~ReferenceCountedBuffer()

DDASReadout::ReferenceCountedBuffer::~ReferenceCountedBuffer ( )
virtual

Destructor.

It's currently an error to destroy the object if it has references. Otherwise, just free any storage that's been allocated.

Member Function Documentation

◆ dereference()

void DDASReadout::ReferenceCountedBuffer::dereference ( )

Remove a reference to the storage.

Deincrement the reference counter.

◆ isReferenced()

bool DDASReadout::ReferenceCountedBuffer::isReferenced ( )

Are there references to the object?

Returns
bool
Return values
trueIf the number of references is > 0.
falseOtherwise.

◆ operator uint16_t *()

DDASReadout::ReferenceCountedBuffer::operator uint16_t * ( )
inline

◆ operator uint32_t *()

DDASReadout::ReferenceCountedBuffer::operator uint32_t * ( )
inline

◆ operator uint8_t *()

DDASReadout::ReferenceCountedBuffer::operator uint8_t * ( )
inline

◆ reference()

void DDASReadout::ReferenceCountedBuffer::reference ( )

Add a reference to the storage.

Increment the reference counter.

◆ resize()

void DDASReadout::ReferenceCountedBuffer::resize ( size_t  newSize)

Resize the storage.

Parameters
newSizeThe new size in bytes.
Exceptions
std::logic_errorIf there are references.
std::bad_allocIf the memory allocation fails.

This must not be done when there are references as the resize will invalidate all pointers. Therefore if there are references, a std::logic_error is thrown.

Note
If newSize < s_size no resize is done but the exception can still be thrown.

Member Data Documentation

◆ s_pData

void* DDASReadout::ReferenceCountedBuffer::s_pData

Data pointer.

◆ s_references

size_t DDASReadout::ReferenceCountedBuffer::s_references

Number of references.

◆ s_size

size_t DDASReadout::ReferenceCountedBuffer::s_size

Number of bytes of data.


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