dispenso 1.6.2
A library for task parallelism
Loading...
Searching...
No Matches
dispenso::ConcurrentObjectArena< T, Index, alignment > Struct Template Reference

#include <concurrent_object_arena.h>

Public Member Functions

 ConcurrentObjectArena (const Index minBuffSize, const Index initialSize=0)
 
 ConcurrentObjectArena (const ConcurrentObjectArena< T, Index, alignment > &other)
 
 ConcurrentObjectArena (ConcurrentObjectArena< T, Index, alignment > &&other) noexcept
 
Index grow_by (const Index delta)
 
Index size () const
 
Index capacity () const
 
Index numBuffers () const
 
const T * getBuffer (const Index index) const
 
T * getBuffer (const Index index)
 
Index getBufferSize (const Index index) const
 

Detailed Description

template<class T, class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
struct dispenso::ConcurrentObjectArena< T, Index, alignment >

ConcurrentObjectArena is an indexed sequence container that allows concurrent insertion to its end. Insertion never invalidates pointers or references to the rest of the elements. As opposet to std::vector, the elements of a ConcurrentObjectArena are not stored contiguously. In memory it is sequence of individually allocated fixed-size arrays, with additional bookkeeping. The size of arrays is always power of two (to optimize indexed access)

   buffers  |<────     bufferSize      ────>|
     ┌─┐    ┌──────────────────────────────┐
     │*├───>│                              │
     ├─┤    ├──────────────────────────────┤
     │*├───>│                              │
     ├─┤    ├──────────────────────────────┤
     │*├───>│                              │
     └─┘    └──────────────────────────────┘
*

Elements are default-constructed by grow_by() and destroyed when the arena is destroyed or assigned over. Copying an arena requires T to be trivially copyable.

If an element's constructor throws, grow_by() destroys the elements it had already built and rethrows. The slots it reserved stay inside size() (which never decreases) as a gap that holds no objects: the caller must not access them, and the arena skips them when destroying its elements.

Definition at line 69 of file concurrent_object_arena.h.

Constructor & Destructor Documentation

◆ ConcurrentObjectArena() [1/3]

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
dispenso::ConcurrentObjectArena< T, Index, alignment >::ConcurrentObjectArena ( const Index minBuffSize,
const Index initialSize = 0 )
inlineexplicit

Construct a ConcurrentObjectArena with given or bigger contiguous array size

Parameters
minBuffSizeThe minimum size of the internal buffer. If given size is not power of 2 the closest bigger power of two would be chosen.
initialSizeThe number of elements to construct initially (default 0).

Definition at line 78 of file concurrent_object_arena.h.

◆ ConcurrentObjectArena() [2/3]

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
dispenso::ConcurrentObjectArena< T, Index, alignment >::ConcurrentObjectArena ( const ConcurrentObjectArena< T, Index, alignment > & other)
inline

Copy constructor

Definition at line 99 of file concurrent_object_arena.h.

◆ ConcurrentObjectArena() [3/3]

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
dispenso::ConcurrentObjectArena< T, Index, alignment >::ConcurrentObjectArena ( ConcurrentObjectArena< T, Index, alignment > && other)
inlinenoexcept

Move constructor

Definition at line 126 of file concurrent_object_arena.h.

◆ ~ConcurrentObjectArena()

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
dispenso::ConcurrentObjectArena< T, Index, alignment >::~ConcurrentObjectArena ( )
inline

Definition at line 138 of file concurrent_object_arena.h.

Member Function Documentation

◆ capacity()

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
Index dispenso::ConcurrentObjectArena< T, Index, alignment >::capacity ( ) const
inline

The current capacity of the object arena. Concurrency safe.

Returns
The current capacity. Note that elements can be appended concurrently

Definition at line 260 of file concurrent_object_arena.h.

◆ getBuffer() [1/2]

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
T * dispenso::ConcurrentObjectArena< T, Index, alignment >::getBuffer ( const Index index)
inline

Get the pointer to the buffer. Concurrency safe.

Parameters
indexindex of the buffer
Returns
The pointer to the buffer.

Definition at line 286 of file concurrent_object_arena.h.

◆ getBuffer() [2/2]

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
const T * dispenso::ConcurrentObjectArena< T, Index, alignment >::getBuffer ( const Index index) const
inline

Get the pointer to the buffer. Concurrency safe.

Parameters
indexindex of the buffer
Returns
The pointer to the buffer.

Definition at line 277 of file concurrent_object_arena.h.

◆ getBufferSize()

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
Index dispenso::ConcurrentObjectArena< T, Index, alignment >::getBufferSize ( const Index index) const
inline

Get the used buffer size. not concurrency safe.

Parameters
indexindex of the buffer.
Returns
The used buffer size.

Definition at line 295 of file concurrent_object_arena.h.

◆ grow_by()

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
Index dispenso::ConcurrentObjectArena< T, Index, alignment >::grow_by ( const Index delta)
inline

Grow a container

This function is thread safe and never invalidates pointers or references to the rest of the elements. It is lock-free if new elements can be placed in current buffer. It locks if it allocates a new buffer. The new elements are default-constructed. If a constructor throws, the elements already built by this call are destroyed and the exception is rethrown; the reserved slots are left as a gap (see the class documentation).

Parameters
deltaNew size of the container will be delta elements bigger.
Returns
index of the first element of the allocated group.

Definition at line 182 of file concurrent_object_arena.h.

◆ numBuffers()

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
Index dispenso::ConcurrentObjectArena< T, Index, alignment >::numBuffers ( ) const
inline

Number of the internal buffers. Concurrency safe.

Returns
The current number of buffers. Note that buffers can be appended concurrently

Definition at line 268 of file concurrent_object_arena.h.

◆ size()

template<class T , class Index = size_t, size_t alignment = dispenso::kCacheLineSize>
Index dispenso::ConcurrentObjectArena< T, Index, alignment >::size ( ) const
inline

Get the size of the object arena. Concurrency safe.

Returns
The number of elements in the object arena. Note that elements can be appended concurrently with this call.

Definition at line 252 of file concurrent_object_arena.h.


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