![]() |
SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Memory allocator for allocating dynamic memory. More...
#include <stk_memory_allocator.h>
Classes | |
| class | Stats |
| Snapshot of the memory allocator's statistics. More... | |
Static Public Member Functions | |
| static void * | Allocate (size_t size) __stk_weak |
| Allocate the memory chunk. | |
| static void | Free (void *ptr) __stk_weak |
| Free the memory chunk. | |
| static Stats | GetStats () __stk_weak |
| Get stats of memory allocation. | |
| template<typename TElement, typename... TArgs> | |
| static TElement * | AllocateOneT (TArgs &&...args) |
| Allocate a single element and construct it in-place. | |
| template<typename TElement, typename... TArgs> | |
| static TElement * | AllocateArrayT (size_t count, TArgs &&...args) |
| Allocate an array of elements and default/copy-construct each one. | |
| template<typename TElement> | |
| static void | FreeOneT (TElement *ptr) |
| Destroy and free a single element allocated via AllocateOne(). | |
| template<typename TElement> | |
| static void | FreeArrayT (TElement *ptr, size_t count) |
| Destroy and free an array allocated via AllocateT(). | |
Static Public Attributes | |
| static const size_t | CAPACITY_DEFAULT = 12288U |
| Default memory pool capacity in bytes. | |
Memory allocator for allocating dynamic memory.
Example of your trivial implementation:
Definition at line 55 of file stk_memory_allocator.h.
|
static |
Allocate the memory chunk.
| [in] | size | Size of the memory chunk. |
Definition at line 44 of file stk_c_memory.cpp.
References malloc().
Referenced by AllocateArrayT(), AllocateOneT(), and pvPortMalloc().
|
inlinestatic |
Allocate an array of elements and default/copy-construct each one.
| [in] | count | Number of elements to allocate. |
| [in] | args | Constructor arguments forwarded to every element. |
Definition at line 158 of file stk_memory_allocator.h.
References __stk_constexpr_cpp17, Allocate(), STK_ASSERT, and STK_UNUSED.
|
inlinestatic |
Allocate a single element and construct it in-place.
| [in] | args | Constructor arguments forwarded to TElement. |
Definition at line 134 of file stk_memory_allocator.h.
References __stk_constexpr_cpp17, Allocate(), STK_ASSERT, and STK_UNUSED.
|
static |
Free the memory chunk.
| [in] | ptr | Pointer to the memory chunk. nullptr is allowed and results in noop. |
Definition at line 45 of file stk_c_memory.cpp.
References free().
Referenced by FreeArrayT(), FreeOneT(), and vPortFree().
|
inlinestatic |
Destroy and free an array allocated via AllocateT().
| [in] | ptr | Pointer to the first element. nullptr is allowed and results in noop. |
| [in] | count | Number of elements (must match the count passed to AllocateT()). |
Definition at line 207 of file stk_memory_allocator.h.
References __stk_constexpr_cpp17, Free(), STK_ASSERT, and STK_UNUSED.
Referenced by stk::memory::BlockMemoryPool::~BlockMemoryPool().
|
inlinestatic |
Destroy and free a single element allocated via AllocateOne().
| [in] | ptr | Pointer to the element. nullptr is allowed and results in noop. |
Definition at line 187 of file stk_memory_allocator.h.
References __stk_constexpr_cpp17, Free(), and STK_ASSERT.
|
static |
Get stats of memory allocation.
Definition at line 107 of file freertos_stk.cpp.
References s_MemStats.
|
static |
Default memory pool capacity in bytes.
Definition at line 60 of file stk_memory_allocator.h.
Referenced by stk::memory::MemoryAllocator::Stats::Stats().