![]() |
ChibiOS/RT Architecture - Reference Manual - Guides |
|
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.
In order to use the memory pools APIs the 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... | |
Defines | |
| #define | _MEMORYPOOL_DATA(name, size, provider) {NULL, MEM_ALIGN_SIZE(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. | |
Functions | |
| void | chPoolInit (MemoryPool *mp, size_t size, memgetfunc_t provider) |
| Initializes an empty memory pool. | |
| 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 (or adds) an object into (to) a memory pool. | |
| void | chPoolFree (MemoryPool *mp, void *objp) |
| Releases (or adds) an object into (to) a memory pool. | |
| #define _MEMORYPOOL_DATA | ( | name, | ||
| size, | ||||
| provider | ||||
| ) | {NULL, MEM_ALIGN_SIZE(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 68 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 81 of file chmempools.h.
| void chPoolInit | ( | MemoryPool * | mp, | |
| size_t | size, | |||
| memgetfunc_t | provider | |||
| ) |
Initializes an empty memory pool.
align_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 58 of file chmempools.c.
References chDbgCheck, MEM_ALIGN_SIZE, MemoryPool::mp_next, MemoryPool::mp_object_size, and MemoryPool::mp_provider.
| 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 74 of file chmempools.c.
References chDbgCheck, 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 95 of file chmempools.c.
References chPoolAllocI(), chSysLock, and chSysUnlock.
Referenced by chThdCreateFromMemoryPool().

| void chPoolFreeI | ( | MemoryPool * | mp, | |
| void * | objp | |||
| ) |
Releases (or adds) an object into (to) a memory pool.
align_t type.| [in] | mp | pointer to a MemoryPool structure |
| [in] | objp | the pointer to the object to be released or added |
Definition at line 114 of file chmempools.c.
References chDbgCheck, MEM_IS_ALIGNED, MemoryPool::mp_next, and pool_header::ph_next.
Referenced by chPoolFree().
| void chPoolFree | ( | MemoryPool * | mp, | |
| void * | objp | |||
| ) |
Releases (or adds) an object into (to) a memory pool.
| [in] | mp | pointer to a MemoryPool structure |
| [in] | objp | the pointer to the object to be released or added |
Definition at line 132 of file chmempools.c.
References chPoolFreeI(), chSysLock, and chSysUnlock.
Referenced by chThdRelease().

1.7.1