Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
buffer_pool.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
7#include <cstdint>
8#include <memory>
9#include <vector>
10
12{
13
46 class buffer_pool : public std::enable_shared_from_this<buffer_pool>
47 {
48 public:
54 explicit buffer_pool(size_t pool_size = 32, size_t default_capacity = 8192);
55
59 ~buffer_pool() noexcept;
60
69 auto acquire(size_t min_capacity = 0) -> std::shared_ptr<std::vector<uint8_t>>;
70
75 auto get_stats() const -> std::pair<size_t, size_t>;
76
80 auto clear() -> void;
81
82 private:
89 auto release(std::vector<uint8_t>* buffer) -> void;
90
91 private:
92 class impl;
93 std::unique_ptr<impl> pimpl_;
94 };
95
96} // namespace kcenon::network::utils
Thread-safe memory pool for reusable byte buffers.
Definition buffer_pool.h:47
buffer_pool(size_t pool_size=32, size_t default_capacity=8192)
Constructs a buffer 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.
std::unique_ptr< impl > pimpl_
Definition buffer_pool.h:93
auto release(std::vector< uint8_t > *buffer) -> void
Returns a buffer to the pool.
auto acquire(size_t min_capacity=0) -> std::shared_ptr< std::vector< uint8_t > >
Acquires a buffer from the pool.
Utility components for network_system.