Define and manage fixed-size memory pools of objects of a given type. More...
#include <MemoryPool.h>
Public Member Functions | |
| MemoryPool () | |
| Create and Initialize a memory pool. More... | |
| ~MemoryPool () | |
| Destroy a memory pool. More... | |
| T * | alloc () |
| Allocate a memory block from a memory pool, without blocking. More... | |
| T * | try_alloc () |
| Allocate a memory block from a memory pool, without blocking. More... | |
| T * | alloc_for (uint32_t millisec) |
| Allocate a memory block from a memory pool, optionally blocking. More... | |
| T * | try_alloc_for (Kernel::Clock::duration_u32 rel_time) |
| Allocate a memory block from a memory pool, optionally blocking. More... | |
| T * | alloc_until (uint64_t millisec) |
| Allocate a memory block from a memory pool, blocking. More... | |
| T * | try_alloc_until (Kernel::Clock::time_point abs_time) |
| Allocate a memory block from a memory pool, blocking. More... | |
| T * | calloc () |
| Allocate a memory block from a memory pool, without blocking, and set memory block to zero. More... | |
| T * | try_calloc () |
| Allocate a memory block from a memory pool, without blocking, and set memory block to zero. More... | |
| T * | calloc_for (uint32_t millisec) |
| Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero. More... | |
| T * | try_calloc_for (Kernel::Clock::duration_u32 rel_time) |
| Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero. More... | |
| T * | calloc_until (uint64_t millisec) |
| Allocate a memory block from a memory pool, blocking, and set memory block to zero. More... | |
| T * | try_calloc_until (Kernel::Clock::time_point abs_time) |
| Allocate a memory block from a memory pool, blocking, and set memory block to zero. More... | |
| osStatus | free (T *block) |
| Free a memory block. More... | |
Define and manage fixed-size memory pools of objects of a given type.
| T | data type of a single object (element). |
| queue_sz | maximum number of objects (elements) in the memory pool. |
Definition at line 59 of file MemoryPool.h.
| MemoryPool | ( | ) |
Create and Initialize a memory pool.
Definition at line 66 of file MemoryPool.h.
| ~MemoryPool | ( | ) |
Destroy a memory pool.
Definition at line 82 of file MemoryPool.h.
| T* alloc | ( | ) |
Allocate a memory block from a memory pool, without blocking.
Definition at line 94 of file MemoryPool.h.
| T* alloc_for | ( | uint32_t | millisec | ) |
Allocate a memory block from a memory pool, optionally blocking.
| millisec | timeout value (osWaitForever to wait forever) |
try_alloc_for. For example use try_alloc_for(5s) rather than alloc_for(5000). Definition at line 130 of file MemoryPool.h.
| T* alloc_until | ( | uint64_t | millisec | ) |
Allocate a memory block from a memory pool, blocking.
| millisec | absolute timeout time, referenced to Kernel::get_ms_count(). |
try_alloc_until. For example use try_alloc_until(Kernel::Clock::now() + 5s) rather than alloc_until(Kernel::get_ms_count() + 5000). Definition at line 160 of file MemoryPool.h.
| T* calloc | ( | ) |
Allocate a memory block from a memory pool, without blocking, and set memory block to zero.
Definition at line 197 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.
| millisec | timeout value (osWaitForever to wait forever) |
try_calloc_for. For example use try_calloc_for(5s) rather than calloc_for(5000). Definition at line 224 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.
| millisec | absolute timeout time, referenced to Kernel::get_ms_count(). |
try_calloc_until. For example use try_calloc_until(Kernel::Clock::now() + 5s) rather than calloc_until(Kernel::get_ms_count() + 5000). Definition at line 257 of file MemoryPool.h.
| osStatus free | ( | T * | block | ) |
Free a memory block.
This method works like std::free or std::allocator<T>::deallocate in that any object in the memory is not destroyed. For types with a non-trivial destructor that destructor must be called manually before freeing the memory.
Example:
| block | address of the allocated memory block to be freed. |
Definition at line 300 of file MemoryPool.h.
| T* try_alloc | ( | ) |
Allocate a memory block from a memory pool, without blocking.
This method works like std::malloc or std::allocator<T>::allocate in that the returned memory block is not initialized. For types with a non-trivial constructor placement new must be used to construct an object in the returned storage.
Example:
Definition at line 117 of file MemoryPool.h.
| T* try_alloc_for | ( | Kernel::Clock::duration_u32 | rel_time | ) |
Allocate a memory block from a memory pool, optionally blocking.
| rel_time | timeout value (Kernel::wait_for_u32_forever to wait forever) |
Definition at line 142 of file MemoryPool.h.
| T* try_alloc_until | ( | Kernel::Clock::time_point | abs_time | ) |
Allocate a memory block from a memory pool, blocking.
| abs_time | absolute timeout time, referenced to Kernel::Clock. |
Definition at line 176 of file MemoryPool.h.
| T* try_calloc | ( | ) |
Allocate a memory block from a memory pool, without blocking, and set memory block to zero.
Definition at line 207 of file MemoryPool.h.
| T* try_calloc_for | ( | Kernel::Clock::duration_u32 | rel_time | ) |
Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero.
| rel_time | timeout value (Kernel::wait_for_u32_forever to wait forever) |
Definition at line 235 of file MemoryPool.h.
| T* try_calloc_until | ( | Kernel::Clock::time_point | abs_time | ) |
Allocate a memory block from a memory pool, blocking, and set memory block to zero.
| abs_time | absolute timeout time, referenced to Kernel::Clock. |
Definition at line 272 of file MemoryPool.h.