NSCL DDAS
12.1-001
Support for XIA DDAS at FRIB
|
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... | |
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.
DDASReadout::ReferenceCountedBuffer::ReferenceCountedBuffer | ( | size_t | initialSize = 0 | ) |
Construct the buffer.
initialSize | Initial size in bytes allocated to the buffer (default = 0). |
std::bad_alloc | Buffer 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.
|
virtual |
Destructor.
It's currently an error to destroy the object if it has references. Otherwise, just free any storage that's been allocated.
void DDASReadout::ReferenceCountedBuffer::dereference | ( | ) |
Remove a reference to the storage.
Deincrement the reference counter.
bool DDASReadout::ReferenceCountedBuffer::isReferenced | ( | ) |
Are there references to the object?
true | If the number of references is > 0. |
false | Otherwise. |
|
inline |
|
inline |
|
inline |
void DDASReadout::ReferenceCountedBuffer::reference | ( | ) |
Add a reference to the storage.
Increment the reference counter.
void DDASReadout::ReferenceCountedBuffer::resize | ( | size_t | newSize | ) |
Resize the storage.
newSize | The new size in bytes. |
std::logic_error | If there are references. |
std::bad_alloc | If 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.
void* DDASReadout::ReferenceCountedBuffer::s_pData |
Data pointer.
size_t DDASReadout::ReferenceCountedBuffer::s_references |
Number of references.
size_t DDASReadout::ReferenceCountedBuffer::s_size |
Number of bytes of data.