CppCommon
1.0.4.1
C++ Common Library
|
Memory pool manager class. More...
#include <allocator_pool.h>
Public Member Functions | |
PoolMemoryManager (TAuxMemoryManager &auxiliary) | |
Initialize memory pool manager with an auxiliary memory manager. More... | |
PoolMemoryManager (TAuxMemoryManager &auxiliary, size_t page, size_t pages=0) | |
Initialize memory pool manager with an auxiliary memory manager, single page size and max pages count. More... | |
PoolMemoryManager (TAuxMemoryManager &auxiliary, void *buffer, size_t capacity) | |
Initialize memory pool manager with an auxiliary memory manager and a given buffer. More... | |
PoolMemoryManager (const PoolMemoryManager &)=delete | |
PoolMemoryManager (PoolMemoryManager &&)=delete | |
~PoolMemoryManager () | |
PoolMemoryManager & | operator= (const PoolMemoryManager &)=delete |
PoolMemoryManager & | operator= (PoolMemoryManager &&)=delete |
size_t | allocated () const noexcept |
Allocated memory in bytes. More... | |
size_t | allocations () const noexcept |
Count of active memory allocations. More... | |
size_t | page () const noexcept |
Page size in bytes. More... | |
size_t | pages () const noexcept |
Max pages size. More... | |
size_t | max_size () const noexcept |
Maximum memory block size, that could be allocated by the memory manager. More... | |
TAuxMemoryManager & | auxiliary () noexcept |
Auxiliary memory manager. More... | |
void * | malloc (size_t size, size_t alignment=alignof(std::max_align_t)) |
Allocate a new memory block of the given size. More... | |
void | free (void *ptr, size_t size) |
Free the previously allocated memory block. More... | |
void | reset () |
Reset the memory manager. More... | |
void | reset (size_t page, size_t pages=0) |
Reset the memory manager with a given signle page size and max pages count. More... | |
void | reset (void *buffer, size_t capacity) |
Reset the memory manager with a given buffer. More... | |
void | clear () |
Clear memory pool. More... | |
Memory pool manager class.
Memory pool manager uses a pre-allocated memory buffer or several memory pages in order to create an effective free-list data structure, that allows to allocate and free memory.
During the allocation memory pool manager will return a first-fit memory block in the free list with concatenating joint blocks to avoid memory defragmentation.
If the allocated block is huge and does not fit into the memory pool page then it will be allocated directly from auxiliary memory manager.
Not thread-safe.
Definition at line 32 of file allocator_pool.h.
|
inlineexplicit |
Initialize memory pool manager with an auxiliary memory manager.
Memory pool will have unlimited pages of size 65536.
auxiliary | - Auxiliary memory manager |
Definition at line 41 of file allocator_pool.h.
|
inlineexplicit |
Initialize memory pool manager with an auxiliary memory manager, single page size and max pages count.
auxiliary | - Auxiliary memory manager |
page | - Page size in bytes |
pages | - Max pages count. Zero value means unlimited count (default is 0) |
Definition at line 12 of file allocator_pool.inl.
|
inlineexplicit |
Initialize memory pool manager with an auxiliary memory manager and a given buffer.
auxiliary | - Auxiliary memory manager |
buffer | - Pool buffer |
capacity | - Pool buffer capacity |
Definition at line 27 of file allocator_pool.inl.
|
delete |
|
delete |
|
inline |
Definition at line 58 of file allocator_pool.h.
|
inlinenoexcept |
Allocated memory in bytes.
Definition at line 64 of file allocator_pool.h.
|
inlinenoexcept |
Count of active memory allocations.
Definition at line 66 of file allocator_pool.h.
|
inlinenoexcept |
Auxiliary memory manager.
Definition at line 77 of file allocator_pool.h.
|
inline |
Clear memory pool.
Definition at line 336 of file allocator_pool.inl.
|
inline |
Free the previously allocated memory block.
ptr | - Pointer to the memory block |
size | - Block size |
Definition at line 202 of file allocator_pool.inl.
|
inline |
Allocate a new memory block of the given size.
size | - Block size |
alignment | - Block alignment (default is alignof(std::max_align_t)) |
Definition at line 42 of file allocator_pool.inl.
|
inlinenoexcept |
Maximum memory block size, that could be allocated by the memory manager.
Definition at line 74 of file allocator_pool.h.
|
delete |
|
delete |
|
inlinenoexcept |
Page size in bytes.
Definition at line 69 of file allocator_pool.h.
|
inlinenoexcept |
Max pages size.
Definition at line 71 of file allocator_pool.h.
|
inline |
Reset the memory manager.
Definition at line 255 of file allocator_pool.inl.
|
inline |
Reset the memory manager with a given signle page size and max pages count.
page | - Page size in bytes |
pages | - Max pages count. Zero value means unlimited count (default is 0) |
Definition at line 274 of file allocator_pool.inl.
|
inline |
Reset the memory manager with a given buffer.
buffer | - Pool buffer |
capacity | - Pool buffer capacity |
Definition at line 308 of file allocator_pool.inl.