Ok

Dependencies:   mbed_rtos_types Mutex mbed_rtos_storage mbed Semaphore

Embed: (wiki syntax)

« Back to documentation index

MemoryPool< T, pool_sz > Class Template Reference

MemoryPool< T, pool_sz > Class Template Reference
[MemoryPool class]

Define and manage fixed-size memory pools of objects of a given type. More...

#include <MemoryPool.h>

Inherits mbed::NonCopyable< MemoryPool< T, pool_sz > >.

Public Member Functions

 MemoryPool ()
 Create and Initialize a memory pool.
 ~MemoryPool ()
 Destroy a memory pool.
T * alloc (void)
 Allocate a memory block from a memory pool, without blocking.
T * alloc_for (uint32_t millisec)
 Allocate a memory block from a memory pool, optionally blocking.
T * alloc_until (uint64_t millisec)
 Allocate a memory block from a memory pool, blocking.
T * calloc (void)
 Allocate a memory block from a memory pool, without blocking, and set memory block to zero.
T * calloc_for (uint32_t millisec)
 Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero.
T * calloc_until (uint64_t millisec)
 Allocate a memory block from a memory pool, blocking, and set memory block to zero.
osStatus free (T *block)
 Free a memory block.

Detailed Description

template<typename T, uint32_t pool_sz>
class rtos::MemoryPool< T, pool_sz >

Define and manage fixed-size memory pools of objects of a given type.

Template Parameters:
Tdata type of a single object (element).
queue_szmaximum number of objects (elements) in the memory pool.
Note:
Memory considerations: The memory pool data store and control structures will be created on current thread's stack, both for the mbed OS and underlying RTOS objects (static or dynamic RTOS memory pools are not being used).

Definition at line 51 of file MemoryPool.h.


Constructor & Destructor Documentation

MemoryPool (  )

Create and Initialize a memory pool.

Note:
You cannot call this function from ISR context.

Definition at line 58 of file MemoryPool.h.

~MemoryPool (  )

Destroy a memory pool.

Note:
You cannot call this function from ISR context.

Definition at line 74 of file MemoryPool.h.


Member Function Documentation

T* alloc ( void   )

Allocate a memory block from a memory pool, without blocking.

Returns:
address of the allocated memory block or nullptr in case of no memory available.
Note:
You may call this function from ISR context.

Definition at line 84 of file MemoryPool.h.

T* alloc_for ( uint32_t  millisec )

Allocate a memory block from a memory pool, optionally blocking.

Parameters:
millisectimeout value (osWaitForever to wait forever)
Returns:
address of the allocated memory block or nullptr in case of no memory available.
Note:
You may call this function from ISR context if the millisec parameter is set to 0.

Definition at line 95 of file MemoryPool.h.

T* alloc_until ( uint64_t  millisec )

Allocate a memory block from a memory pool, blocking.

Parameters:
millisecabsolute timeout time, referenced to Kernel::get_ms_count().
Returns:
address of the allocated memory block or nullptr in case of no memory available.
Note:
You cannot call this function from ISR context.
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.

Definition at line 110 of file MemoryPool.h.

T* calloc ( void   )

Allocate a memory block from a memory pool, without blocking, and set memory block to zero.

Returns:
address of the allocated memory block or nullptr in case of no memory available.
Note:
You may call this function from ISR context.

Definition at line 129 of file MemoryPool.h.

T* calloc_for ( uint32_t  millisec )

Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero.

Parameters:
millisectimeout value (osWaitForever to wait forever)
Returns:
address of the allocated memory block or nullptr in case of no memory available.
Note:
You may call this function from ISR context if the millisec parameter is set to 0.

Definition at line 144 of file MemoryPool.h.

T* calloc_until ( uint64_t  millisec )

Allocate a memory block from a memory pool, blocking, and set memory block to zero.

Parameters:
millisecabsolute timeout time, referenced to Kernel::get_ms_count().
Returns:
address of the allocated memory block or nullptr in case of no memory available.
Note:
You cannot call this function from ISR context.
the underlying RTOS may have a limit to the maximum wait time due to internal 32-bit computations, but this is guaranteed to work if the wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded, the wait will time out earlier than specified.

Definition at line 163 of file MemoryPool.h.

osStatus free ( T *  block )

Free a memory block.

Parameters:
blockaddress of the allocated memory block to be freed.
Returns:
osOK on successful deallocation, osErrorParameter if given memory block id is nullptr or invalid, or osErrorResource if given memory block is in an invalid memory pool state.
Note:
You may call this function from ISR context.

Definition at line 180 of file MemoryPool.h.