Native QF Memory Pool. More...
#include "qmpool.hpp"
Public Member Functions | |
QMPool () | |
void | init (void *const poolSto, std::uint_fast32_t const poolSize, std::uint_fast16_t const blockSize) noexcept |
void * | get (std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept |
void | put (void *const block, std::uint_fast8_t const qsId) noexcept |
QMPoolSize | getBlockSize () const noexcept |
QMPoolCtr | getNMin () const noexcept |
QMPoolCtr | getNFree () const noexcept |
void * | getFromISR (std::uint_fast16_t const margin, std::uint_fast8_t const qsId) noexcept |
void | putFromISR (void *const b, std::uint_fast8_t const qsId) noexcept |
Private Member Functions | |
QMPool (QEQueue const &other)=delete | |
QMPool & | operator= (QMPool const &other)=delete |
Private Attributes | |
QFreeBlock * | m_start |
QFreeBlock * | m_end |
QFreeBlock *volatile | m_free_head |
QMPoolSize | m_blockSize |
QMPoolCtr | m_nTot |
QMPoolCtr volatile | m_nFree |
QMPoolCtr | m_nMin |
Native QF Memory Pool.
A fixed block-size memory pool is a very fast and efficient data structure for dynamic allocation of fixed block-size chunks of memory. A memory pool offers fast and deterministic allocation and recycling of memory blocks and is not subject to fragmentation.
The QP::QMPool class describes the native QF memory pool, which can be used as the event pool for mutable event allocation, or as a fast, deterministic fixed block-size heap for any other objects in your application.
Definition at line 101 of file qmpool.hpp.
|
inline |
Default constructor of QP::QMPool
Definition at line 112 of file qmpool.hpp.
|
privatedelete |
|
noexcept |
Initializes the native QF memory pool
Initialize a fixed block-size memory pool by providing it with the pool memory to manage, size of this memory, and the block size.
[in] | poolSto | pointer to the memory buffer for pool storage |
[in] | poolSize | size of the storage buffer in bytes |
[in] | blockSize | fixed-size of the memory blocks in bytes |
qf_mem:100
poolSto
pointer is properly aligned. In particular, it must be possible to efficiently store a pointer at the location pointed to by poolSto
. Internally, the QMPool_init() function rounds up the block size blockSize
so that it can fit an integer number of pointers. This is done to achieve proper alignment of the blocks within the pool.poolSize
/ blockSize
). You can check the capacity of the pool by calling the QF_getPoolMin() function.Backward Traceability
Definition at line 71 of file qf_mem.cpp.
|
noexcept |
Obtain a memory block from a memory pool.
The function allocates a memory block from the pool and returns a pointer to the block back to the caller.
[in] | margin | the minimum number of unused blocks still available in the pool after the allocation. |
[in] | qsId | QS-id of this state machine (for QS local filter) |
me
must be initialized before any events can be requested from it. Also, the QMPool_get() function uses internally a QF critical section, so you should be careful not to call it from within a critical section when nesting of critical section is not supported.Backward Traceability
Definition at line 138 of file qf_mem.cpp.
|
noexcept |
Recycles a memory block back to a memory pool.
Recycle a memory block to the fixed block-size memory pool.
[in] | block | pointer to the memory block that is being recycled |
[in] | qsId | QS-id of this state machine (for QS local filter) |
qf_mem:200
Backward Traceability
Definition at line 215 of file qf_mem.cpp.
|
noexcept |
Definition at line 254 of file qf_mem.cpp.
|
inlinenoexcept |
Definition at line 132 of file qmpool.hpp.
|
inlinenoexcept |
Definition at line 135 of file qmpool.hpp.
|
noexcept |
|
noexcept |
|
private |
Start of the memory managed by this memory pool
Definition at line 103 of file qmpool.hpp.
|
private |
End of the memory managed by this memory pool
Definition at line 104 of file qmpool.hpp.
|
private |
Head of linked list of free memory blocks
Definition at line 105 of file qmpool.hpp.
|
private |
Memory block size [bytes] held by this fixed-size pool.
Definition at line 106 of file qmpool.hpp.
|
private |
Total number of memory blocks in this pool
Definition at line 107 of file qmpool.hpp.
|
private |
Number of free memory blocks remaining in the pool at this point
Definition at line 108 of file qmpool.hpp.
|
private |
Minimum number of free blocks ever present in this pool
This attribute remembers the low watermark of the pool, which provides a valuable information for sizing event pools. (
Definition at line 109 of file qmpool.hpp.