SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::memory::MemoryAllocator::Weak Struct Reference

Weak backend hooks of the allocator: the part that the application (or one of the stk_memory_allocator_*.h headers) implements. More...

#include <stk_memory_allocator.h>

Collaboration diagram for stk::memory::MemoryAllocator::Weak:

Static Public Member Functions

static void * Allocate (size_t size) __stk_weak
 Allocate the memory chunk (backend hook).
static void Free (void *ptr) __stk_weak
 Free the memory chunk (backend hook).
static Stats GetStats () __stk_weak
 Get stats of memory allocation (backend hook, optional).

Detailed Description

Weak backend hooks of the allocator: the part that the application (or one of the stk_memory_allocator_*.h headers) implements.

STK never defines these functions. If no definition is linked in, on most toolchains the symbols resolve to address 0 and a call is a jump to null (a run-time fault), not a linker error.

Warning
Do NOT call these functions directly from application code: they are unguarded. Use the checked front-end instead: MemoryAllocator::Allocate(), Free() and GetStats().
Note
Allocate() and Free() are required; GetStats() is optional (the front-end returns empty Stats if it is not provided).
See also
IsAvailable(), Allocate(), Free(), GetStats()

Definition at line 306 of file stk_memory_allocator.h.

Member Function Documentation

◆ Allocate()

void * stk::memory::MemoryAllocator::Weak::Allocate ( size_t size)
static

Allocate the memory chunk (backend hook).

Parameters
[in]sizeSize of the memory chunk.
Returns
Pointer to the allocated memory chunk (aligned to at least MIN_ALIGNMENT), nullptr if allocator failed to allocate it.

Definition at line 76 of file stk_memory_allocator_default.h.

77{
78 return detail::DefaultHeapPool().TryAlloc(size);
79}
static BytePool & DefaultHeapPool()
Get the default heap pool, creating it on the first call.
void * TryAlloc(size_t size)
Non-blocking allocation attempt.

References stk::memory::detail::DefaultHeapPool(), and stk::memory::BytePool::TryAlloc().

Referenced by stk::memory::MemoryAllocator::Allocate(), and stk::memory::MemoryAllocator::IsAvailable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Free()

void stk::memory::MemoryAllocator::Weak::Free ( void * ptr)
static

Free the memory chunk (backend hook).

Parameters
[in]ptrPointer to the memory chunk. nullptr is allowed and results in noop.

Definition at line 81 of file stk_memory_allocator_default.h.

82{
83 if (ptr != nullptr)
84 {
85 const bool freed = detail::DefaultHeapPool().Free(ptr);
86 STK_UNUSED(freed);
87 }
88}
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:715
bool Free(void *ptr)
Return a previously allocated block to the pool.

References stk::memory::detail::DefaultHeapPool(), stk::memory::BytePool::Free(), and STK_UNUSED.

Referenced by stk::memory::MemoryAllocator::Free(), and stk::memory::MemoryAllocator::IsAvailable().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetStats()

stk::memory::MemoryAllocator::Stats stk::memory::MemoryAllocator::Weak::GetStats ( )
static

Get stats of memory allocation (backend hook, optional).

Returns
Stats structure.

Definition at line 90 of file stk_memory_allocator_default.h.

91{
93}
MemoryAllocator::Stats GetStats() const
Get a consistent O(1) statistics snapshot in the same format as MemoryAllocator::GetStats().

References stk::memory::detail::DefaultHeapPool(), and stk::memory::BytePool::GetStats().

Referenced by stk::memory::MemoryAllocator::GetStats().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this struct was generated from the following files: