|
ChibiOS/RT
2.5.1 |
|
Memory Pools related APIs and services.
The Memory Pools APIs allow to allocate/free fixed size objects in constant time and reliably without memory fragmentation problems.
Memory Pools do not enforce any alignment constraint on the contained object however the objects must be properly aligned to contain a pointer to void.
CH_USE_MEMPOOLS option must be enabled in chconf.h. Data Structures | |
| struct | pool_header |
| Memory pool free object header. More... | |
| struct | MemoryPool |
| Memory pool descriptor. More... | |
Functions | |
| void | chPoolInit (MemoryPool *mp, size_t size, memgetfunc_t provider) |
| Initializes an empty memory pool. | |
| void | chPoolLoadArray (MemoryPool *mp, void *p, size_t n) |
| Loads a memory pool with an array of static objects. | |
| void * | chPoolAllocI (MemoryPool *mp) |
| Allocates an object from a memory pool. | |
| void * | chPoolAlloc (MemoryPool *mp) |
| Allocates an object from a memory pool. | |
| void | chPoolFreeI (MemoryPool *mp, void *objp) |
| Releases an object into a memory pool. | |
| void | chPoolFree (MemoryPool *mp, void *objp) |
| Releases an object into a memory pool. | |
Macro Functions | |
| #define | chPoolAdd(mp, objp) chPoolFree(mp, objp) |
| Adds an object to a memory pool. | |
| #define | chPoolAddI(mp, objp) chPoolFreeI(mp, objp) |
| Adds an object to a memory pool. | |
Defines | |
| #define | _MEMORYPOOL_DATA(name, size, provider) {NULL, size, provider} |
| Data part of a static memory pool initializer. | |
| #define | MEMORYPOOL_DECL(name, size, provider) MemoryPool name = _MEMORYPOOL_DATA(name, size, provider) |
| Static memory pool initializer in hungry mode. | |
| void chPoolInit | ( | MemoryPool * | mp, |
| size_t | size, | ||
| memgetfunc_t | provider | ||
| ) |
Initializes an empty memory pool.
stkalign_t type size.| [out] | mp | pointer to a MemoryPool structure |
| [in] | size | the size of the objects contained in this memory pool, the minimum accepted size is the size of a pointer to void. |
| [in] | provider | memory provider function for the memory pool or NULL if the pool is not allowed to grow automatically |
Definition at line 57 of file chmempools.c.
References chDbgCheck, MemoryPool::mp_next, MemoryPool::mp_object_size, and MemoryPool::mp_provider.
| void chPoolLoadArray | ( | MemoryPool * | mp, |
| void * | p, | ||
| size_t | n | ||
| ) |
Loads a memory pool with an array of static objects.
| [in] | mp | pointer to a MemoryPool structure |
| [in] | p | pointer to the array first element |
| [in] | n | number of elements in the array |
Definition at line 79 of file chmempools.c.
References chDbgCheck, chPoolAdd, and MemoryPool::mp_object_size.
| void * chPoolAllocI | ( | MemoryPool * | mp | ) |
Allocates an object from a memory pool.
| [in] | mp | pointer to a MemoryPool structure |
| NULL | if pool is empty. |
Definition at line 100 of file chmempools.c.
References chDbgCheck, chDbgCheckClassI(), MemoryPool::mp_next, MemoryPool::mp_object_size, MemoryPool::mp_provider, and pool_header::ph_next.
Referenced by chPoolAlloc().

| void * chPoolAlloc | ( | MemoryPool * | mp | ) |
Allocates an object from a memory pool.
| [in] | mp | pointer to a MemoryPool structure |
| NULL | if pool is empty. |
Definition at line 123 of file chmempools.c.
References chPoolAllocI(), chSysLock, and chSysUnlock.
Referenced by chThdCreateFromMemoryPool().

| void chPoolFreeI | ( | MemoryPool * | mp, |
| void * | objp | ||
| ) |
Releases an object into a memory pool.
| [in] | mp | pointer to a MemoryPool structure |
| [in] | objp | the pointer to the object to be released |
Definition at line 144 of file chmempools.c.
References chDbgCheck, chDbgCheckClassI(), MemoryPool::mp_next, and pool_header::ph_next.
Referenced by chPoolFree().

| void chPoolFree | ( | MemoryPool * | mp, |
| void * | objp | ||
| ) |
Releases an object into a memory pool.
| [in] | mp | pointer to a MemoryPool structure |
| [in] | objp | the pointer to the object to be released |
Definition at line 166 of file chmempools.c.
References chPoolFreeI(), chSysLock, and chSysUnlock.
Referenced by chThdRelease().

| #define _MEMORYPOOL_DATA | ( | name, | |
| size, | |||
| provider | |||
| ) | {NULL, size, provider} |
Data part of a static memory pool initializer.
This macro should be used when statically initializing a memory pool that is part of a bigger structure.
| [in] | name | the name of the memory pool variable |
| [in] | size | size of the memory pool contained objects |
| [in] | provider | memory provider function for the memory pool |
Definition at line 62 of file chmempools.h.
| #define MEMORYPOOL_DECL | ( | name, | |
| size, | |||
| provider | |||
| ) | MemoryPool name = _MEMORYPOOL_DATA(name, size, provider) |
Static memory pool initializer in hungry mode.
Statically initialized memory pools require no explicit initialization using chPoolInit().
| [in] | name | the name of the memory pool variable |
| [in] | size | size of the memory pool contained objects |
| [in] | provider | memory provider function for the memory pool or NULL if the pool is not allowed to grow automatically |
Definition at line 75 of file chmempools.h.
| #define chPoolAdd | ( | mp, | |
| objp | |||
| ) | chPoolFree(mp, objp) |
Adds an object to a memory pool.
stkalign_t type. chPoolFree() and has been added for clarity.| [in] | mp | pointer to a MemoryPool structure |
| [in] | objp | the pointer to the object to be added |
Definition at line 97 of file chmempools.h.
Referenced by chPoolLoadArray().
| #define chPoolAddI | ( | mp, | |
| objp | |||
| ) | chPoolFreeI(mp, objp) |
Adds an object to a memory pool.
stkalign_t type. chPoolFree() and has been added for clarity.| [in] | mp | pointer to a MemoryPool structure |
| [in] | objp | the pointer to the object to be added |
Definition at line 114 of file chmempools.h.