Native QF Memory Pool. More...
#include "qmpool.h"
Public Member Functions | |
void | QMPool_init (QMPool *const me, void *const poolSto, uint_fast32_t const poolSize, uint_fast16_t const blockSize) |
Initializes the native QF memory pool. | |
void * | QMPool_get (QMPool *const me, uint_fast16_t const margin, uint_fast8_t const qsId) |
Obtain a memory block from a memory pool. | |
void | QMPool_put (QMPool *const me, void *const block, uint_fast8_t const qsId) |
Recycles a memory block back to a memory pool. | |
Private Attributes | |
QFreeBlock * | start |
Start of the memory managed by this memory pool. | |
QFreeBlock * | end |
End of the memory managed by this memory pool. | |
QFreeBlock *volatile | free_head |
Head of linked list of free memory blocks. | |
QMPoolSize | blockSize |
Memory block size [bytes] held by this fixed-size pool. | |
QMPoolCtr | nTot |
Total number of memory blocks in this pool. | |
QMPoolCtr volatile | nFree |
Number of free memory blocks remaining in the pool at this point. | |
QMPoolCtr | nMin |
Minimum number of free blocks ever present in this pool. | |
uintptr_t | free_head_dis |
QMPoolCtr | nFree_dis |
Native QF Memory Pool.
The 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.
void QMPool_init | ( | QMPool *const | me, |
void *const | poolSto, | ||
uint_fast32_t const | poolSize, | ||
uint_fast16_t const | blockSize ) |
Initializes the native QF memory pool.
[in,out] | me | current instance pointer (see oop) |
[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.void * QMPool_get | ( | QMPool *const | me, |
uint_fast16_t const | margin, | ||
uint_fast8_t const | qsId ) |
Obtain a memory block from a memory pool.
[in,out] | me | current instance pointer (see oop) |
[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.void QMPool_put | ( | QMPool *const | me, |
void *const | block, | ||
uint_fast8_t const | qsId ) |
Recycles a memory block back to a memory pool.
[in,out] | me | current instance pointer (see oop) |
[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
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |