|
Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
|
Thread-safe fixed-size block memory allocator. More...
#include <memory_pool.h>

Public Member Functions | |
| memory_pool () | |
| Default constructor with default configuration. | |
| memory_pool (const memory_pool_config &config) | |
| Construct with configuration. | |
| ~memory_pool () | |
| memory_pool (const memory_pool &)=delete | |
| memory_pool & | operator= (const memory_pool &)=delete |
| memory_pool (memory_pool &&other) noexcept | |
| memory_pool & | operator= (memory_pool &&other) noexcept |
| common::Result< void * > | allocate () |
| Allocate a memory block. | |
| common::VoidResult | deallocate (void *ptr) |
| Deallocate a memory block. | |
| template<typename T , typename... Args> | |
| common::Result< T * > | allocate_object (Args &&... args) |
| Allocate and construct an object. | |
| template<typename T > | |
| common::VoidResult | deallocate_object (T *obj) |
| Destroy and deallocate an object. | |
| size_t | available_blocks () const |
| Get number of available blocks. | |
| size_t | total_blocks () const |
| Get total number of blocks. | |
| size_t | block_size () const |
| Get block size. | |
| const memory_pool_statistics & | get_statistics () const |
| Get pool statistics. | |
| void | reset_statistics () |
| Reset statistics. | |
Private Member Functions | |
| void | initialize_pool () |
| bool | grow_pool () |
| bool | is_owned_block (void *ptr) const |
| void | update_peak_usage () |
Private Attributes | |
| memory_pool_config | config_ |
| size_t | block_size_ |
| size_t | total_blocks_ |
| std::vector< void * > | free_blocks_ |
| std::vector< void * > | memory_chunks_ |
| std::mutex | mutex_ |
| memory_pool_statistics | stats_ |
Thread-safe fixed-size block memory allocator.
This pool pre-allocates memory blocks of fixed size for efficient allocation/deallocation without heap fragmentation.
Definition at line 171 of file memory_pool.h.
|
inline |
Default constructor with default configuration.
Definition at line 176 of file memory_pool.h.
|
inlineexplicit |
Construct with configuration.
| config | Pool configuration |
Definition at line 182 of file memory_pool.h.
References initialize_pool().

|
inline |
Definition at line 189 of file memory_pool.h.
References detail::aligned_free_impl(), and memory_chunks_.

|
delete |
|
inlinenoexcept |
Definition at line 200 of file memory_pool.h.
References kcenon::monitoring::other.
|
inline |
Allocate a memory block.
Definition at line 230 of file memory_pool.h.
References kcenon::monitoring::memory_pool_statistics::allocation_failures, free_blocks_, grow_pool(), mutex_, kcenon::monitoring::resource_unavailable, stats_, kcenon::monitoring::memory_pool_statistics::total_allocations, and update_peak_usage().
Referenced by allocate_object(), TEST_F(), TEST_F(), and TEST_F().


|
inline |
Allocate and construct an object.
| T | The object type |
| Args | Constructor argument types |
| args | Constructor arguments |
Definition at line 281 of file memory_pool.h.
References allocate(), block_size_, kcenon::monitoring::invalid_argument, and kcenon::monitoring::resource_unavailable.
Referenced by TEST_F(), and TEST_F().


|
inline |
Get number of available blocks.
Definition at line 317 of file memory_pool.h.
References free_blocks_, and mutex_.
Referenced by TEST_F(), and TEST_F().

|
inline |
Get block size.
Definition at line 334 of file memory_pool.h.
References block_size_.
|
inline |
Deallocate a memory block.
| ptr | Pointer to the block to deallocate |
Definition at line 255 of file memory_pool.h.
References free_blocks_, kcenon::monitoring::invalid_argument, is_owned_block(), mutex_, stats_, and kcenon::monitoring::memory_pool_statistics::total_deallocations.
Referenced by deallocate_object(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().


|
inline |
Destroy and deallocate an object.
| T | The object type |
| obj | Pointer to the object |
Definition at line 304 of file memory_pool.h.
References deallocate(), and kcenon::monitoring::invalid_argument.
Referenced by TEST_F().


|
inline |
|
inlineprivate |
Definition at line 372 of file memory_pool.h.
References detail::aligned_alloc_impl(), kcenon::monitoring::memory_pool_config::alignment, block_size_, config_, free_blocks_, kcenon::monitoring::memory_pool_config::max_blocks, memory_chunks_, and total_blocks_.
Referenced by allocate().


|
inlineprivate |
Definition at line 354 of file memory_pool.h.
References detail::aligned_alloc_impl(), kcenon::monitoring::memory_pool_config::alignment, block_size_, config_, free_blocks_, memory_chunks_, and total_blocks_.
Referenced by memory_pool().


|
inlineprivate |
Definition at line 400 of file memory_pool.h.
References block_size_, config_, kcenon::monitoring::memory_pool_config::initial_blocks, memory_chunks_, and total_blocks_.
Referenced by deallocate().

|
delete |
|
inlinenoexcept |
Definition at line 210 of file memory_pool.h.
References detail::aligned_free_impl(), block_size_, config_, free_blocks_, memory_chunks_, kcenon::monitoring::other, stats_, and total_blocks_.

|
inline |
Reset statistics.
Definition at line 349 of file memory_pool.h.
References kcenon::monitoring::memory_pool_statistics::reset(), and stats_.

|
inline |
Get total number of blocks.
Definition at line 326 of file memory_pool.h.
References total_blocks_.
Referenced by TEST_F().

|
inlineprivate |
Definition at line 418 of file memory_pool.h.
References free_blocks_, kcenon::monitoring::memory_pool_statistics::peak_usage, stats_, and total_blocks_.
Referenced by allocate().

|
private |
Definition at line 429 of file memory_pool.h.
Referenced by allocate_object(), block_size(), grow_pool(), initialize_pool(), is_owned_block(), and operator=().
|
private |
Definition at line 428 of file memory_pool.h.
Referenced by grow_pool(), initialize_pool(), is_owned_block(), and operator=().
|
private |
Definition at line 431 of file memory_pool.h.
Referenced by allocate(), available_blocks(), deallocate(), grow_pool(), initialize_pool(), operator=(), and update_peak_usage().
|
private |
Definition at line 432 of file memory_pool.h.
Referenced by grow_pool(), initialize_pool(), is_owned_block(), operator=(), and ~memory_pool().
|
mutableprivate |
Definition at line 433 of file memory_pool.h.
Referenced by allocate(), available_blocks(), and deallocate().
|
mutableprivate |
Definition at line 434 of file memory_pool.h.
Referenced by allocate(), deallocate(), get_statistics(), operator=(), reset_statistics(), and update_peak_usage().
|
private |
Definition at line 430 of file memory_pool.h.
Referenced by grow_pool(), initialize_pool(), is_owned_block(), operator=(), total_blocks(), and update_peak_usage().