ChibiOS/RT Logo ChibiOS/RT

Architecture - Reference Manual - Guides

Data Structures | Defines | Functions

Memory Pools
[Memory Management]

Collaboration diagram for Memory Pools:


Description

Memory Pools related APIs and services.

Operation mode

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 Documentation

#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.

Parameters:
[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().

Parameters:
[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.


Function Documentation

void chPoolInit ( MemoryPool mp,
size_t  size,
memgetfunc_t  provider 
)

Initializes an empty memory pool.

Note:
The size is internally aligned to be a multiple of the align_t type size.
Parameters:
[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.

Parameters:
[in] mp pointer to a MemoryPool structure
Returns:
The pointer to the allocated object.
Return values:
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.

Parameters:
[in] mp pointer to a MemoryPool structure
Returns:
The pointer to the allocated object.
Return values:
NULL if pool is empty.

Definition at line 95 of file chmempools.c.

References chPoolAllocI(), chSysLock, and chSysUnlock.

Referenced by chThdCreateFromMemoryPool().

Here is the call graph for this function:

void chPoolFreeI ( MemoryPool mp,
void *  objp 
)

Releases (or adds) an object into (to) a memory pool.

Note:
The object is assumed to be of the right size for the specified memory pool.
The object is assumed to be memory aligned to the size of align_t type.
Parameters:
[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.

Note:
The object is assumed to be of the right size for the specified memory pool.
Parameters:
[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().

Here is the call graph for this function:


Generated on Sun Nov 28 2010 14:09:56 for ChibiOS/RT by doxygen 1.7.1