Native QF memory pool class.
More...
#include <qmpool.hpp>
Native QF memory pool class.
- Description
- 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 fragmenation.
The QP::QMPool class describes the native QF memory pool, which can be used as the event pool for dynamic event allocation, or as a fast, deterministic fixed block-size heap for any other objects in your application.
- Note
- The QP::QMPool class contains only data members for managing a memory pool, but does not contain the pool storage, which must be provided externally during the pool initialization.
-
The native QF event pool is configured by defining the macro QF_EPOOL_TYPE_ as QP::QMPool in the specific QF port header file.
Definition at line 106 of file qmpool.hpp.
◆ QMPool() [1/2]
public default constructor
- Description
- Default constructor of a fixed block-size memory pool.
- Note
- The memory pool is not ready to use directly after instantiation. To become ready, the QP::QMPool::init() must be called to give the pool memory, size of this memory, and the block size to manage.
Definition at line 63 of file qf_mem.cpp.
◆ QMPool() [2/2]
disallow copying of QMPools
disallow assigning of QMPools
◆ init()
Initializes the native QF event pool.
- Description
- Initialize a fixed block-size memory pool by providing it with the pool memory to manage, size of this memory, and the block size.
- Parameters
-
[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 |
- Attention
- The caller of QP::QMPool::init() must make sure that the
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 QP::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.
- Note
- Due to the rounding of block size the actual capacity of the pool might be less than (
poolSize
/ blockSize
). You can check the capacity of the pool by calling the QP::QF::getPoolMin() function.
-
This function is not protected by a critical section, because it is intended to be called only during the initialization of the system, when interrupts are not allowed yet.
-
Many QF ports use memory pools to implement the event pools.
- Precondition
- The memory block must be valid and the poolSize must fit at least one free block and the blockSize must not be too close to the top of the dynamic range
Definition at line 103 of file qf_mem.cpp.
◆ get()
Obtains a memory block from a memory pool.
- Description
- The function allocates a memory block from the pool and returns a pointer to the block back to the caller.
- Parameters
-
[in] | margin | the minimum number of unused blocks still available in the pool after the allocation. |
[in] | qs_id | QS-id of this state machine (for QS local filter) |
- Note
- This function can be called from any task level or ISR level.
-
The memory pool must be initialized before any events can be requested from it. Also, the QP::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.
- Attention
- An allocated block must be later returned back to the same pool from which it has been allocated.
- See also
- QP::QMPool::put()
Definition at line 224 of file qf_mem.cpp.
◆ put()
Returns a memory block back to a memory pool.
- Description
- Recycle a memory block to the fixed block-size memory pool.
- Parameters
-
[in] | b | pointer to the memory block that is being recycled |
[in] | qs_id | QS-id of this state machine (for QS local filter) |
- Attention
- The recycled block must be allocated from the same memory pool to which it is returned.
- Note
- This function can be called from any task level or ISR level.
- See also
- QP::QMPool::get()
- Precondition
- # free blocks cannot exceed the total # blocks and the block pointer must be in range to come from this pool.
Definition at line 174 of file qf_mem.cpp.
◆ getBlockSize()
return the fixed block-size of the blocks managed by this pool
Definition at line 150 of file qmpool.hpp.
◆ operator=()
◆ QF
◆ QS
◆ m_start
start of the memory managed by this memory pool
Definition at line 110 of file qmpool.hpp.
◆ m_end
end of the memory managed by this memory pool
Definition at line 113 of file qmpool.hpp.
◆ m_free_head
void* volatile m_free_head |
|
private |
head of linked list of free blocks
Definition at line 116 of file qmpool.hpp.
◆ m_blockSize
maximum block size (in bytes)
Definition at line 119 of file qmpool.hpp.
◆ m_nTot
total number of blocks
Definition at line 122 of file qmpool.hpp.
◆ m_nFree
number of free blocks remaining
Definition at line 125 of file qmpool.hpp.
◆ m_nMin
minimum number of free blocks ever present in this pool
- Note
- This attribute remembers the low watermark of the pool, which provides a valuable information for sizing event pools.
- See also
- QP::QF::getPoolMin().
Definition at line 133 of file qmpool.hpp.
The documentation for this class was generated from the following files: