22#include <kcenon/common/utils/object_pool.h>
47 [[nodiscard]]
auto hit_ratio() const noexcept ->
double {
52 return static_cast<double>(
pool_hits.load(std::memory_order_relaxed))
53 /
static_cast<double>(total);
61 pool_hits.store(0, std::memory_order_relaxed);
100 [[nodiscard]]
auto size() const noexcept -> std::
size_t {
108 [[nodiscard]]
auto capacity() const noexcept -> std::
size_t {
109 return data_.capacity();
116 [[nodiscard]]
auto data() noexcept -> uint8_t* {
return data_.data(); }
122 [[nodiscard]]
auto data() const noexcept -> const uint8_t* {
138 [[nodiscard]]
auto vector() const noexcept -> const std::
vector<uint8_t>& {
145 [[nodiscard]]
auto operator[](std::size_t index) -> uint8_t& {
152 [[nodiscard]]
auto operator[](std::size_t index)
const ->
const uint8_t& {
171 :
pool_(initial_size) {
172 pool_.reserve(initial_size);
180 template <
typename... Args>
183 auto ptr =
pool_.acquire(&reused, std::forward<Args>(args)...);
208 return pool_.available();
216 pool_.reserve(count);
276 auto
acquire_pdv(uint8_t context_id = 0,
bool is_command = false,
366 buffer->resize(size);
378 bool is_command =
false,
tracked_pdu_pool< p_data_tf_pdu > p_data_pool_
auto acquire_p_data_tf() -> tracked_pdu_pool< p_data_tf_pdu >::unique_ptr_type
Acquire a p_data_tf_pdu from the pool.
void reserve_buffers(std::size_t count)
Reserve capacity in buffer pool.
tracked_pdu_pool< presentation_data_value > pdv_pool_
static constexpr std::size_t DEFAULT_PDV_POOL_SIZE
static constexpr std::size_t DEFAULT_PDATA_POOL_SIZE
auto pdv_statistics() const noexcept -> const pdu_pool_statistics &
Get PDV pool statistics.
auto acquire_buffer() -> tracked_pdu_pool< pooled_buffer >::unique_ptr_type
Acquire a byte buffer from the pool.
static constexpr std::size_t DEFAULT_BUFFER_POOL_SIZE
Default pool sizes.
auto buffer_statistics() const noexcept -> const pdu_pool_statistics &
Get buffer pool statistics.
void reset_statistics()
Reset all statistics.
tracked_pdu_pool< pooled_buffer > buffer_pool_
void reserve_pdvs(std::size_t count)
Reserve capacity in PDV pool.
void clear_all()
Clear all pools.
static auto get() noexcept -> pdu_buffer_pool &
Get the global PDU buffer pool instance.
auto acquire_pdv(uint8_t context_id=0, bool is_command=false, bool is_last=true) -> tracked_pdu_pool< presentation_data_value >::unique_ptr_type
Acquire a presentation_data_value from the pool.
auto p_data_statistics() const noexcept -> const pdu_pool_statistics &
Get P-DATA-TF pool statistics.
Pooled byte buffer for PDU data.
void clear() noexcept
Clear the buffer contents (keeps capacity)
auto vector() const noexcept -> const std::vector< uint8_t > &
Get const reference to underlying vector.
auto data() noexcept -> uint8_t *
Get raw pointer to data.
auto data() const noexcept -> const uint8_t *
Get const raw pointer to data.
auto operator[](std::size_t index) const -> const uint8_t &
Const array access operator.
auto size() const noexcept -> std::size_t
Get the current size.
void reserve(std::size_t capacity)
Reserve capacity.
auto vector() noexcept -> std::vector< uint8_t > &
Get reference to underlying vector.
auto operator[](std::size_t index) -> uint8_t &
Array access operator.
void resize(std::size_t new_size)
Resize the buffer.
auto capacity() const noexcept -> std::size_t
Get the current capacity.
std::vector< uint8_t > data_
Pool wrapper with statistics tracking for PDU buffers.
std::unique_ptr< T, std::function< void(T *)> > unique_ptr_type
void clear()
Clear the pool and release all memory.
pdu_pool_statistics stats_
auto statistics() const noexcept -> const pdu_pool_statistics &
Get the pool statistics.
auto available() const -> std::size_t
Get the number of available objects in the pool.
auto acquire(Args &&... args) -> unique_ptr_type
Acquire an object from the pool.
void reserve(std::size_t count)
Reserve additional capacity in the pool.
kcenon::common::utils::ObjectPool< T > pool_type
tracked_pdu_pool(std::size_t initial_size=64)
auto make_pooled_pdu_buffer() -> tracked_pdu_pool< pooled_buffer >::unique_ptr_type
Create a pooled byte buffer.
auto make_pooled_p_data_tf() -> tracked_pdu_pool< p_data_tf_pdu >::unique_ptr_type
Create a pooled p_data_tf_pdu.
auto make_pooled_pdv(uint8_t context_id=0, bool is_command=false, bool is_last=true) -> tracked_pdu_pool< presentation_data_value >::unique_ptr_type
Create a pooled presentation_data_value.
Statistics for PDU buffer pool usage monitoring.
auto hit_ratio() const noexcept -> double
Calculate hit ratio (0.0 to 1.0)
std::atomic< uint64_t > pool_hits
void reset() noexcept
Reset all statistics.
std::atomic< uint64_t > total_releases
std::atomic< uint64_t > pool_misses
std::atomic< uint64_t > total_acquisitions
std::atomic< uint64_t > total_bytes_allocated
Presentation Data Value (PDV) item for P-DATA-TF.