![]() |
GemaCoreLib
The GeMA Core library
|
A virtual class representing a buffer of T objects that can be appended in a thread-safe way, growing the buffer as needed. More...
#include <gmAppendBuffer.h>
Public Member Functions | |
virtual | ~GmAppendBuffer () |
Virtual destructor. | |
virtual void | clear ()=0 |
Releases the memory used by the buffer, returning it to a recently constructed state. Must be followed by a call to reserve() before the object is able to do any further appends. Must be called from the main thread only. | |
virtual void | reserve (size_t size)=0 |
Informs the buffer of the expected number of entries that will be filled by (concurrent) calls to append. Can only be called from the main thread. More... | |
virtual void | append (const T &val)=0 |
Appends val to the buffer in a thread safe way. Can grow the buffer if needed. | |
virtual void | appendFromThread (int tid, const T &val)=0 |
Appends val to the buffer in a thread safe way, using the given tid to access TLS storage. Can grow the buffer if needed. | |
virtual size_t | size () const =0 |
Returns the number of entries in the buffer. Must be called from the main thread only. | |
virtual T * | data ()=0 |
Returns a vector filled with the buffer data. After this call, NO calls to append() can be made without a prior call to clear(). More... | |
virtual size_t | usedMemory () const =0 |
Returns an estimative of the total memory used by the buffer in bytes. | |
A virtual class representing a buffer of T objects that can be appended in a thread-safe way, growing the buffer as needed.
After composing the buffer by calls to append() from multiple threads, the resulting data can be transformed into a vector by calling data(). This function will either return the internal vector, if possible, or will allocate a new vector and fill it with the buffer data (releasing the previous data to free resources). After a call to data(), a call to clear() MUST be made before any further calls to append().
The adopted strategy for synchronization and buffer growing depends on the concrete class that was instanced.
|
pure virtual |
Returns a vector filled with the buffer data. After this call, NO calls to append() can be made without a prior call to clear().
If the buffer has internally only one vector, that vector will be returned. Otherwise, a new vector will be created, the buffer data copied to the new vector and the old buffers released. Either way, the returned buffer is valid until the append buffer is destroyed or until a call to clear().
Must be called from the main thread only.
Returns NULL if the vector could not be created. In that case, leaves the original buffers untouched.
|
pure virtual |
Informs the buffer of the expected number of entries that will be filled by (concurrent) calls to append. Can only be called from the main thread.
Uses a 64 bits value for the size since this list can grow quite quickly and a 32 bits limit can be achieved. An hex27 element with 5 dofs per node generates a 135 x 135 local matrix, translating into 135 * 135 = 18.225 calls to append() per mesh element. That will overflow a standard int with less than 120.000 elements.
Implemented in GmSingleAppendBuffer< GmSparseMatrixTripletData< T >, GmSparseMatrixTripletBuffer< T > >, and GmPerThreadAppendBuffer< GmSparseMatrixTripletData< T >, GmSparseMatrixTripletBuffer< T > >.