|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Thread-safe memory pool for reusable byte buffers. More...
#include <buffer_pool.h>


Classes | |
| class | impl |
Public Member Functions | |
| buffer_pool (size_t pool_size=32, size_t default_capacity=8192) | |
| Constructs a buffer pool. | |
| ~buffer_pool () noexcept | |
| Destructor. | |
| auto | acquire (size_t min_capacity=0) -> std::shared_ptr< std::vector< uint8_t > > |
| Acquires a buffer from the pool. | |
| auto | get_stats () const -> std::pair< size_t, size_t > |
| Gets current pool statistics. | |
| auto | clear () -> void |
| Clears the pool and releases all cached buffers. | |
Private Member Functions | |
| auto | release (std::vector< uint8_t > *buffer) -> void |
| Returns a buffer to the pool. | |
Private Attributes | |
| std::unique_ptr< impl > | pimpl_ |
Thread-safe memory pool for reusable byte buffers.
Definition at line 46 of file buffer_pool.h.
|
explicit |
Constructs a buffer pool.
| pool_size | Maximum number of buffers to cache |
| default_capacity | Default capacity for new buffers |
Definition at line 134 of file buffer_pool.cpp.
|
noexcept |
Destructor.
Definition at line 139 of file buffer_pool.cpp.
References kcenon::network::utils::buffer_pool::impl::clear(), and pimpl_.

| auto kcenon::network::utils::buffer_pool::acquire | ( | size_t | min_capacity = 0 | ) | -> std::shared_ptr<std::vector<uint8_t>> |
Acquires a buffer from the pool.
| min_capacity | Minimum required capacity |
If no suitable buffer is available in the pool, creates a new one. Buffer is returned to pool automatically when the shared_ptr is destroyed.
Definition at line 151 of file buffer_pool.cpp.
| auto kcenon::network::utils::buffer_pool::clear | ( | ) | -> void |
Clears the pool and releases all cached buffers.
Definition at line 166 of file buffer_pool.cpp.
| auto kcenon::network::utils::buffer_pool::get_stats | ( | ) | const -> std::pair<size_t, size_t> |
Gets current pool statistics.
Definition at line 161 of file buffer_pool.cpp.
References kcenon::network::utils::buffer_pool::impl::get_stats(), and pimpl_.

|
private |
Returns a buffer to the pool.
| buffer | Buffer to return |
Called automatically by custom deleter when shared_ptr is destroyed.
Definition at line 156 of file buffer_pool.cpp.
|
private |
Definition at line 93 of file buffer_pool.h.
Referenced by get_stats(), and ~buffer_pool().