|
|
Memory pool. More...
Data Structures | |
struct | os_mem_pool_s |
Memory pool structure. More... | |
Defines | |
#define | os_mem_pool_available(m) DOC_HIDDEN |
Gets number of free items in the pool. | |
#define | os_mem_pool_itemsize(m) ((m)->itemsize); |
Gets the size of pool item. | |
Functions | |
os_result_t | os_mem_pool_create (os_mem_pool_t *m, unsigned char log2itemsize, unsigned short capacity) |
Creates memory pool. | |
os_result_t | os_mem_pool_destroy (os_mem_pool_t *m) |
Destroys memory pool. | |
os_result_t | os_mem_pool_alloc (os_mem_pool_t *m, void **item) |
Allocates memory item. | |
os_result_t | os_mem_pool_free (os_mem_pool_t *m, void *item) |
Deallocates memory item. |
Memory pool.
This is implementation of memory pool. The pool is a kind of partition with items of constant size. It works more efficiently than heap allocator. Both operations: allocation and deallocation are simpler and more reliable when memory pool is used. The memory pool has an advantage over heap, the pool has no risk of fragmentation and lack of memory in one continuous part. The cost for this feature is additional memory usage - the items are always the same size. This extra memory consumption can be decreased by matching size of the item to used elements or by creation a set of pools, each one with different size.
#define os_mem_pool_available | ( | m | ) | DOC_HIDDEN |
Gets number of free items in the pool.
[in] | m | pointer to memory pool structure |
#define os_mem_pool_itemsize | ( | m | ) | ((m)->itemsize); |
Gets the size of pool item.
[in] | m | pointer to memory pool structure |
os_result_t os_mem_pool_alloc | ( | os_mem_pool_t * | m, |
void ** | item | ||
) |
Allocates memory item.
The function is thread safe and can be called from ISR.
Allocated memory can be set to zeros or marked with zeros at the beginning (this is selected by config.h)
[in] | m | pointer to pool structure |
[out] | item | pointer to variable where pointer to allocated item will be stored |
os_result_t os_mem_pool_create | ( | os_mem_pool_t * | m, |
unsigned char | log2itemsize, | ||
unsigned short | capacity | ||
) |
Creates memory pool.
This is not thread-safe (use before scheduler is run or before any use of the pool).
[out] | m | pointer to empty structure that will describe the pool |
[in] | log2itemsize | item size must be power of 2, e.g. 1, 2, 4, 8, 16 etc. |
[in] | capacity | number of items in the memory pool |
os_result_t os_mem_pool_destroy | ( | os_mem_pool_t * | m | ) |
Destroys memory pool.
The function is thread safe.
[in] | m | - pointer to pool structure |
os_result_t os_mem_pool_free | ( | os_mem_pool_t * | m, |
void * | item | ||
) |
Deallocates memory item.
The function is thread safe and can be called from ISR.
[in] | m | pointer to pool structure |
[in] | item | pointer to memory that need to be deallocated - returned to the pool. |