PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::core::tracked_pool< T > Class Template Reference

Pool wrapper with statistics tracking. More...

#include <pool_manager.h>

Inheritance diagram for kcenon::pacs::core::tracked_pool< T >:
Inheritance graph
Collaboration diagram for kcenon::pacs::core::tracked_pool< T >:
Collaboration graph

Public Types

using pool_type = kcenon::common::utils::ObjectPool<T>
 
using unique_ptr_type = std::unique_ptr<T, std::function<void(T*)>>
 

Public Member Functions

 tracked_pool (std::size_t initial_size=32)
 
template<typename... Args>
auto acquire (Args &&... args) -> unique_ptr_type
 Acquire an object from the pool.
 
auto statistics () const noexcept -> const pool_statistics &
 Get the pool statistics.
 
auto available () const -> std::size_t
 Get the number of available objects in the pool.
 
void reserve (std::size_t count)
 Reserve additional capacity in the pool.
 
void clear ()
 Clear the pool and release all memory.
 

Private Attributes

pool_type pool_
 
pool_statistics stats_
 

Detailed Description

template<typename T>
class kcenon::pacs::core::tracked_pool< T >

Pool wrapper with statistics tracking.

Template Parameters
TThe type of objects to pool

Definition at line 72 of file pool_manager.h.

Member Typedef Documentation

◆ pool_type

template<typename T >
using kcenon::pacs::core::tracked_pool< T >::pool_type = kcenon::common::utils::ObjectPool<T>

◆ unique_ptr_type

template<typename T >
using kcenon::pacs::core::tracked_pool< T >::unique_ptr_type = std::unique_ptr<T, std::function<void(T*)>>

Constructor & Destructor Documentation

◆ tracked_pool()

template<typename T >
kcenon::pacs::core::tracked_pool< T >::tracked_pool ( std::size_t initial_size = 32)
inlineexplicit

Member Function Documentation

◆ acquire()

template<typename T >
template<typename... Args>
auto kcenon::pacs::core::tracked_pool< T >::acquire ( Args &&... args) -> unique_ptr_type
inline

Acquire an object from the pool.

Parameters
argsArguments forwarded to the object's constructor
Returns
A unique_ptr that returns the object to the pool on destruction
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/pool_manager.h.

Definition at line 88 of file pool_manager.h.

88 {
89 bool reused = false;
90 auto ptr = pool_.acquire(&reused, std::forward<Args>(args)...);
91
92 stats_.total_acquisitions.fetch_add(1, std::memory_order_relaxed);
93 if (reused) {
94 stats_.pool_hits.fetch_add(1, std::memory_order_relaxed);
95 } else {
96 stats_.pool_misses.fetch_add(1, std::memory_order_relaxed);
97 }
98
99 return ptr;
100 }
std::atomic< uint64_t > total_acquisitions
std::atomic< uint64_t > pool_hits
std::atomic< uint64_t > pool_misses

References kcenon::pacs::core::tracked_pool< T >::pool_, kcenon::pacs::core::pool_statistics::pool_hits, kcenon::pacs::core::pool_statistics::pool_misses, kcenon::pacs::core::tracked_pool< T >::stats_, and kcenon::pacs::core::pool_statistics::total_acquisitions.

◆ available()

template<typename T >
auto kcenon::pacs::core::tracked_pool< T >::available ( ) const -> std::size_t
inlinenodiscard

Get the number of available objects in the pool.

Returns
Available object count
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/pool_manager.h.

Definition at line 114 of file pool_manager.h.

114 {
115 return pool_.available();
116 }

References kcenon::pacs::core::tracked_pool< T >::pool_.

◆ clear()

template<typename T >
void kcenon::pacs::core::tracked_pool< T >::clear ( )
inline

Clear the pool and release all memory.

Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/pool_manager.h.

Definition at line 129 of file pool_manager.h.

129 {
130 pool_.clear();
131 }

References kcenon::pacs::core::tracked_pool< T >::pool_.

◆ reserve()

template<typename T >
void kcenon::pacs::core::tracked_pool< T >::reserve ( std::size_t count)
inline

Reserve additional capacity in the pool.

Parameters
countNumber of objects to pre-allocate
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/pool_manager.h.

Definition at line 122 of file pool_manager.h.

122 {
123 pool_.reserve(count);
124 }

References kcenon::pacs::core::tracked_pool< T >::pool_.

◆ statistics()

template<typename T >
auto kcenon::pacs::core::tracked_pool< T >::statistics ( ) const -> const pool_statistics&
inlinenodiscardnoexcept

Get the pool statistics.

Returns
Reference to the statistics
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/core/pool_manager.h.

Definition at line 106 of file pool_manager.h.

106 {
107 return stats_;
108 }

References kcenon::pacs::core::tracked_pool< T >::stats_.

Member Data Documentation

◆ pool_

◆ stats_


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