61 std::lock_guard<std::mutex> lock(
mutex_);
72 return std::make_unique<T>();
76 return std::make_unique<T>();
88 std::lock_guard<std::mutex> lock(
mutex_);
111 std::lock_guard<std::mutex> lock(
mutex_);
123 std::lock_guard<std::mutex> lock(
mutex_);
135 std::lock_guard<std::mutex> lock(
mutex_);
209 if (!local_cache.empty()) {
211 auto obj = std::move(local_cache.back());
212 local_cache.pop_back();
221 size_t batch_size = std::min(
226 for (
size_t i = 0; i < batch_size; ++i) {
235 if (!local_cache.empty()) {
237 auto obj = std::move(local_cache.back());
238 local_cache.pop_back();
246 return std::make_unique<T>();
251 return std::make_unique<T>();
270 local_cache.push_back(std::move(obj));
281 for (
size_t i = 0; i < transfer_count && !local_cache.empty(); ++i) {
284 local_cache.pop_back();
341 thread_local std::vector<std::unique_ptr<T>> cache;
Thread-safe object pool for high-performance memory management.
std::mutex mutex_
Thread safety mutex.
config config_
Pool configuration.
statistics get_statistics() const
Get pool statistics.
object_pool(const config &cfg=config{})
Construct object pool with configuration.
void release(std::unique_ptr< T > obj)
Return an object to the pool.
void initialize_pool()
Initialize pool with initial objects.
std::atomic< size_t > pool_size_
Current pool size.
~object_pool()=default
Destructor.
void clear()
Clear all objects from pool.
std::unique_ptr< T > acquire()
Get an object from the pool.
std::queue< std::unique_ptr< T > > available_objects_
Available objects.
Thread-local cached object pool for improved multi-threaded performance.
static std::vector< std::unique_ptr< T > > & get_local_cache()
Get thread-local cache.
std::unique_ptr< T > acquire()
Get an object from the pool.
thread_local_object_pool(const config &cfg=config{})
Construct thread-local object pool with configuration.
statistics get_statistics() const
Get pool statistics.
std::atomic< size_t > global_pool_hits_
~thread_local_object_pool()=default
Destructor.
void release(std::unique_ptr< T > obj)
Return an object to the pool.
void clear()
Clear all objects from pool.
std::vector< std::unique_ptr< T > > global_pool_
std::atomic< size_t > local_cache_hits_
std::atomic< size_t > new_allocations_
void initialize_pool()
Initialize pool with initial objects.
std::atomic< size_t > global_size_
Error codes specific to the logger system.
Configuration for object pool.
size_t initial_size
Initial pool size.
bool allow_growth
Allow pool to grow beyond initial size.
size_t max_size
Maximum pool size.
Get current pool statistics.
Configuration for thread-local object pool.
bool allow_growth
Allow pool to grow beyond initial size.
size_t local_cache_size
Per-thread cache size.
size_t initial_size
Initial global pool size.
size_t global_max
Maximum total pool size.
Statistics for monitoring pool performance.
size_t global_pool_size
Objects currently in global pool.
size_t local_cache_hits
Acquire from thread-local cache (fast path)
size_t global_size
Total objects managed by pool.
size_t new_allocations
New objects created.
size_t global_pool_hits
Acquire from global pool (batch fetch)