DABC (Data Acquisition Backbone Core)
2.9.9
|
Reference on memory from memory pool. More...
#include <dabc/Buffer.h>
Public Member Functions | |
bool | Append (Buffer &src, bool moverefs=true) throw () |
Append content of provided buffer. More... | |
std::string | AsStdString () |
Convert content of the buffer into std::string. More... | |
bool | CanSafelyChange () const |
Returns true when user can modify buffer content without any doubts. More... | |
BufferSize_t | CopyFrom (const Buffer &srcbuf, BufferSize_t len=0) throw () |
Copy content from source buffer. More... | |
BufferSize_t | CopyFromStr (const char *src, unsigned len=0) throw () |
Copy data from string. More... | |
BufferSize_t | CopyTo (void *ptr, BufferSize_t len) const throw () |
Copy content into provided raw buffer. More... | |
void | CutFromBegin (BufferSize_t len) |
Remove part of buffer from the beginning. More... | |
Buffer | Duplicate () const |
Duplicates instance of Buffer with new segments list independent from source. More... | |
Buffer | GetNextPart (Pointer &ptr, BufferSize_t len, bool allowsegmented=true) throw () |
Returns reference on the part of the memory, referenced by the object. More... | |
Reference | GetPool () const |
Returns reference on the pool, in user code MemoryPoolRef can be used like dabc::Buffer buf = Recv(); dabc::MemoryPoolRef pool = buf.GetPool();. More... | |
BufferSize_t | GetTotalSize () const |
Return total size of all buffer segments. More... | |
unsigned | GetTypeId () const |
Buffer | HandOver () |
Method hands over buffer, that source will be emptied at the end. More... | |
bool | Insert (BufferSize_t pos, Buffer &src, bool moverefs=true) |
Insert content of buffer at specified position. More... | |
bool | IsPool (const Reference &pool) const |
Returns true if buffer produced by the pool provided as reference. More... | |
void | MakeEmpty (unsigned capacity=8) |
Method produce buffer with empty segments list Such buffer can be used to collect segments from other buffers without disturbing other bufs. More... | |
unsigned | NumSegments () const |
Returns number of segment in buffer. More... | |
bool | Prepend (Buffer &src, bool moverefs=true) throw () |
Prepend content of provided buffer. More... | |
unsigned | SegmentId (unsigned n=0) const |
Returns id of the segment, no any boundary checks. More... | |
void * | SegmentPtr (unsigned n=0) const |
Returns pointer on the segment, no any boundary checks. More... | |
MemSegment * | Segments () const |
unsigned | SegmentSize (unsigned n=0) const |
Returns size on the segment, no any boundary checks. More... | |
void | SetTotalSize (BufferSize_t len) |
Set total length of the buffer to specified value Size cannot be bigger than original size of the buffer. More... | |
void | SetTypeId (unsigned tid) |
Public Member Functions inherited from dabc::Reference | |
bool | AddChild (Object *obj) |
Add child to list of object children. More... | |
const char * | ClassName () const |
Return class name of referenced object, if object not assigned, returns "---". More... | |
void | Destroy () throw () |
Release reference and starts destroyment of referenced object. More... | |
Reference | FindChild (const char *name) const |
Searches for child in referenced object. More... | |
bool | GetAllChildRef (ReferencesVector *vect) const |
Return references for all childs. More... | |
Reference | GetChild (unsigned n) const |
Return reference on child n. More... | |
Reference | GetFolder (const std::string &name, bool force=false) throw () |
Return folder of specified name, no special symbols are allowed. More... | |
const char * | GetName () const |
Return name of referenced object, if object not assigned, returns "---". More... | |
Object * | GetObject () const |
Return pointer on the object. More... | |
Object * | GetParent () const |
Returns pointer on parent object. More... | |
Reference | GetParentRef () const |
Returns reference on parent object. More... | |
bool | IsName (const char *name) const |
Returns true if object name is the same as specified one. More... | |
std::string | ItemName (bool compact=true) const |
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call. More... | |
bool | null () const |
Returns true if reference contains nullptr. More... | |
unsigned | NumChilds () const |
Return number of childs in referenced object. More... | |
unsigned | NumReferences () const |
Returns number of references on the object. More... | |
bool | operator! () const |
Returns true if reference contains nullptr. More... | |
bool | operator!= (const Reference &src) const |
Compare operator - return true if references refer to different object. More... | |
bool | operator!= (Object *obj) const |
Compare operator - return true if reference refer to different objects. More... | |
Object * | operator() () const |
Return pointer on the object. More... | |
Reference & | operator<< (Reference &src) throw () |
Move operator - reference moved from source to target. More... | |
Reference & | operator= (const Reference &src) throw () |
Assignment operator - copy reference. More... | |
Reference & | operator= (Object *obj) throw () |
Assignment operator - copy reference. More... | |
bool | operator== (const Reference &src) const |
Compare operator - return true if references refer to same object. More... | |
bool | operator== (Object *obj) const |
Compare operator - return true if reference refer to same object. More... | |
void | Print (int lvl=0, const char *from=0) const |
Show on debug output content of reference. More... | |
Reference (const Reference &src) throw () | |
Copy constructor, if source is transient than source reference will be emptied. More... | |
Reference (Object *obj=nullptr) | |
Constructor, creates reference on the object. More... | |
std::string | RelativeName (const dabc::Reference &topitem) |
Produce name, which can be used to find item, calling topitem.FindChild(). More... | |
void | Release () throw () |
Releases reference on the object. More... | |
bool | RemoveChild (const char *name, bool cleanup=true) |
Remove child with given name and return reference on that child. More... | |
bool | RemoveChilds (bool cleanup=true) |
Remove all childs in referenced object If cleanup true (default) and object is owner, all objects will be destroyed. More... | |
void | SetAutoDestroy (bool on=true) |
Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will be cleared. More... | |
void | SetObject (Object *obj, bool withmutex=true) |
Direct set of object to reference. More... | |
Reference | Take () |
Copy reference to output object. More... | |
virtual | ~Reference () |
Destructor, releases reference on the object. More... | |
Static Public Member Functions | |
static Buffer | CreateBuffer (BufferSize_t sz) throw () |
This static method create independent buffer for any other memory pools Therefore it can be used in standalone case. More... | |
static Buffer | CreateBuffer (const void *ptr, unsigned size, bool owner=false, bool makecopy=false) throw () |
This static method create Buffer instance, which contains pointer on specified peace of memory Therefore it can be used in standalone case. More... | |
Protected Member Functions | |
void | AllocateContainer (unsigned capacity) |
void | Locate (BufferSize_t p, unsigned &seg_indx, unsigned &seg_shift) const |
MemoryPool * | PoolPtr () const |
Protected Member Functions inherited from dabc::Reference | |
bool | AcquireRefWithoutMutex (Reference &ref) |
Special method, which allows to generate new reference when object mutex is locked. More... | |
void | Assign (const Reference &src) |
Method used in copy constructor and assigned operations. More... | |
Mutex * | ObjectMutex () const |
template<class T > | |
bool | verify_object (Object *src, T *&tgt) |
Method used in reference constructor/assignments to verify is object is suitable. More... | |
Friends | |
class | MemoryPool |
Additional Inherited Members | |
Protected Attributes inherited from dabc::Reference | |
Object * | fObj |
pointer on the object More... | |
Reference on memory from memory pool.
Central class for memory usage concept in DABC framework.
All memory for data transfer should be pre-allocated in dabc::MemoryPool. Buffer class provides access to that memory.
Main concepts:
Actual class description need to be done.
|
protected |
Definition at line 172 of file Buffer.cxx.
|
protected |
Definition at line 462 of file Buffer.cxx.
|
protected |
Definition at line 83 of file Buffer.cxx.
dabc::Reference dabc::Buffer::GetPool | ( | ) | const |
Returns reference on the pool, in user code MemoryPoolRef can be used like dabc::Buffer buf = Recv(); dabc::MemoryPoolRef pool = buf.GetPool();.
Definition at line 78 of file Buffer.cxx.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
dabc::BufferSize_t dabc::Buffer::GetTotalSize | ( | ) | const |
Return total size of all buffer segments.
Definition at line 91 of file Buffer.cxx.
dabc::Buffer dabc::Buffer::Duplicate | ( | ) | const |
Duplicates instance of Buffer with new segments list independent from source.
Means original instance will remain as is. Memory which is referenced by Buffer object is not duplicated or copied, means both instances are reference same memory regions. This method can be time consuming, while pool mutex should be locked and reference counter of all segments should be incremented. When created instance destroyed, same operation in reverse order will be performed. Method must be used when new instance should be used in other thread while initial instance Do not duplicate buffer without real need for that.
Definition at line 192 of file Buffer.cxx.
|
inline |
Method hands over buffer, that source will be emptied at the end.
This method creates temporary object which could be deliver to the any other method as argument. At the same time original object forgets buffer and will be empty at the end of the call. Typical place where it should be used is return method when source want to forget buffer itself:
dabc::Buffer MyClass::GetLast() { fLastBuf.SetTotalSize(1024); fLastBuf.SetTypeId(129); return fLastBuf.HandOver(); }
If one wants to keep reference on the memory after such call one should do: ... return fLastBuf; ...
|
inline |
void dabc::Buffer::SetTotalSize | ( | BufferSize_t | len | ) |
Set total length of the buffer to specified value Size cannot be bigger than original size of the buffer.
Definition at line 99 of file Buffer.cxx.
void dabc::Buffer::CutFromBegin | ( | BufferSize_t | len | ) |
Remove part of buffer from the beginning.
Definition at line 139 of file Buffer.cxx.
bool dabc::Buffer::Append | ( | Buffer & | src, |
bool | moverefs = true |
||
) | |||
throw | ( | ||
) |
Append content of provided buffer.
If source buffer belong to other memory pool, content will be copied.
[in] | src | buffer to append |
[in] | moverefs | if true, references moved to the target and source buffer will be emptied |
Definition at line 215 of file Buffer.cxx.
bool dabc::Buffer::Prepend | ( | Buffer & | src, |
bool | moverefs = true |
||
) | |||
throw | ( | ||
) |
Prepend content of provided buffer.
If source buffer belong to other memory pool, content will be copied.
[in] | src | buffer to prepend |
[in] | moverefs | if true, references moved to the target and source buffer will be emptied |
Definition at line 220 of file Buffer.cxx.
bool dabc::Buffer::Insert | ( | BufferSize_t | pos, |
Buffer & | src, | ||
bool | moverefs = true |
||
) |
Insert content of buffer at specified position.
If source buffer belong to other memory pool, content will be copied.
[in] | pos | position at which buffer must be inserted |
[in] | src | buffer to insert |
[in] | moverefs | if true, references moved to the target and source buffer will be emptied |
Definition at line 225 of file Buffer.cxx.
std::string dabc::Buffer::AsStdString | ( | ) |
Convert content of the buffer into std::string.
Definition at line 317 of file Buffer.cxx.
dabc::BufferSize_t dabc::Buffer::CopyFrom | ( | const Buffer & | srcbuf, |
BufferSize_t | len = 0 |
||
) | |||
throw | ( | ||
) |
Copy content from source buffer.
[in] | srcbuf | source buffer |
[in] | len | bytes to copy, if 0 - whole buffer |
Definition at line 333 of file Buffer.cxx.
dabc::BufferSize_t dabc::Buffer::CopyFromStr | ( | const char * | src, |
unsigned | len = 0 |
||
) | |||
throw | ( | ||
) |
Copy data from string.
[in] | src | source string |
[in] | len | bytes copied, (if 0, complete string excluding trailing null) |
Definition at line 339 of file Buffer.cxx.
dabc::BufferSize_t dabc::Buffer::CopyTo | ( | void * | ptr, |
BufferSize_t | len | ||
) | const | ||
throw | ( | ||
) |
Copy content into provided raw buffer.
[in] | ptr | pointer to destination memory |
[in] | len | number of bytes to copy. |
Definition at line 344 of file Buffer.cxx.
dabc::Buffer dabc::Buffer::GetNextPart | ( | Pointer & | ptr, |
BufferSize_t | len, | ||
bool | allowsegmented = true |
||
) | |||
throw | ( | ||
) |
Returns reference on the part of the memory, referenced by the object.
[in,out] | ptr | pointer where next part will be extracted |
[in] | len | length of memory piece (0 - rest size of current segment will be delivered). |
[in] | allowsegmented | defines if return memory peace could be segmented or not. |
This method could be used to manage small peaces of memory in the memory pool with big buffers. For instance, one need some small headers which should managed separately from the main data. Than one need to take big buffer from the pool and extract by small pieces:
// somewhere in the initialization Buffer buf = Pool()->TakeBuffer(64000);
// later in the code Buffer data = Recv(); Buffer hdr = buf.GetNextPart(16) data.Prepend(hdr); Send(data);
Of course, one should check if buffer is expired and one need to take next piece from the memory pool.
TODO: one can exclude pointer and just cut buffer pieces until buffer is empty
Definition at line 349 of file Buffer.cxx.
bool dabc::Buffer::CanSafelyChange | ( | ) | const |
Returns true when user can modify buffer content without any doubts.
It happens when refcnt==1 for each memory segments
Definition at line 451 of file Buffer.cxx.
|
static |
This static method create independent buffer for any other memory pools Therefore it can be used in standalone case.
Definition at line 419 of file Buffer.cxx.
|
static |
This static method create Buffer instance, which contains pointer on specified peace of memory Therefore it can be used in standalone case.
Definition at line 424 of file Buffer.cxx.
|
friend |