diff --git a/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h b/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h index 73485e4..395745a 100644 --- a/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h +++ b/containers_cpp/include/embb/containers/internal/lock_free_tree_value_pool-inl.h @@ -269,6 +269,14 @@ LockFreeTreeValuePool:: } } +template +size_t LockFreeTreeValuePool:: +GetMinimumElementCountForGuaranteedCapacity(size_t capacity) { + // for this value pool, this is just capacity... + return capacity; +} + } // namespace containers } // namespace embb diff --git a/containers_cpp/include/embb/containers/internal/object_pool-inl.h b/containers_cpp/include/embb/containers/internal/object_pool-inl.h index 61711d5..e53f3a9 100644 --- a/containers_cpp/include/embb/containers/internal/object_pool-inl.h +++ b/containers_cpp/include/embb/containers/internal/object_pool-inl.h @@ -117,8 +117,9 @@ size_t ObjectPool::GetCapacity() { template ObjectPool::ObjectPool(size_t capacity) : -capacity(capacity), - p(ReturningTrueIterator(0), ReturningTrueIterator(capacity)) { + capacity(capacity), + p(ReturningTrueIterator(0), ReturningTrueIterator( + ValuePool::GetMinimumElementCountForGuaranteedCapacity(capacity))) { // Allocate the objects (without construction, just get the memory) objects = objectAllocator.allocate(capacity); } diff --git a/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h b/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h index 571f49e..4ea799a 100644 --- a/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h +++ b/containers_cpp/include/embb/containers/internal/wait_free_array_value_pool-inl.h @@ -95,6 +95,14 @@ WaitFreeArrayValuePool::~WaitFreeArrayValuePool() { // free memory allocator.deallocate(pool, static_cast(size)); } + +template +size_t WaitFreeArrayValuePool:: +GetMinimumElementCountForGuaranteedCapacity(size_t capacity) { + // for this value pool, this is just capacity... + return capacity; +} + } // namespace containers } // namespace embb diff --git a/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h b/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h index 2a14d4c..66f43c7 100644 --- a/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h +++ b/containers_cpp/include/embb/containers/lock_free_tree_value_pool.h @@ -278,6 +278,14 @@ class LockFreeTreeValuePool { ); /** + * Due to concurrency effects, a pool might provide less elements than managed + * by it. However, usually one wants to guarantee a minimal capacity. The + * count of elements, that must be given to the pool when to guarantee \c + * capacity elements is computed using this function. + */ + static size_t GetMinimumElementCountForGuaranteedCapacity(size_t capacity); + + /** * Destructs the pool. * * \notthreadsafe diff --git a/containers_cpp/include/embb/containers/wait_free_array_value_pool.h b/containers_cpp/include/embb/containers/wait_free_array_value_pool.h index 8289ca6..68b8ce1 100644 --- a/containers_cpp/include/embb/containers/wait_free_array_value_pool.h +++ b/containers_cpp/include/embb/containers/wait_free_array_value_pool.h @@ -150,6 +150,14 @@ class WaitFreeArrayValuePool { ); /** + * Due to concurrency effects, a pool might provide less elements than managed + * by it. However, usually one wants to guarantee a minimal capacity. The + * count of elements, that must be given to the pool when to guarantee \c + * capacity elements is computed using this function. + */ + static size_t GetMinimumElementCountForGuaranteedCapacity(size_t capacity); + + /** * Destructs the pool. * * \notthreadsafe