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::Stats Struct Reference

Snapshot of the memory allocator's statistics. More...

#include <stk_memory_allocator.h>

Collaboration diagram for stk::memory::MemoryAllocator::Stats:

Public Member Functions

 Stats (size_t capacity_=0U)
void Reset (size_t capacity_)
 Restart the statistics for a pool of the given capacity.
size_t GetCapacity () const
 Get total capacity of the memory pool.
size_t GetAvailable () const
 Get number of bytes currently available for allocation.
void RecordAllocate (size_t size)
 Record successful allocation.
void RecordFree (size_t size)
 Record successful deallocation.
void RecordAllocFail ()
 Record failed allocation request.

Public Attributes

size_t capacity
 Total capacity of the memory pool in bytes.
volatile size_t allocated
 Number of bytes currently allocated (dynamic value).
volatile size_t peak_allocated
 Maximum number of bytes that were allocated at the same time (high watermark).
volatile size_t allocate_count
 Number of successful allocations with Allocate().
volatile size_t free_count
 Number of successful frees with Free().
volatile size_t alloc_fail_count
 Number of allocation requests that could not be satisfied.
volatile size_t min_ever_free
 Minimum free bytes recorded since system start (watermark).

Detailed Description

Snapshot of the memory allocator's statistics.

Note
The Record*() methods are not atomic: they must be called with the allocator lock held (e.g. inside the critical section that protects the allocator state).
BlockMemoryPool and BytePool keep a live instance of this structure and return a copy of it from their GetStats(), so all allocators report identical semantics.

Definition at line 206 of file stk_memory_allocator.h.

Constructor & Destructor Documentation

◆ Stats()

stk::memory::MemoryAllocator::Stats::Stats ( size_t capacity_ = 0U)
inline

Definition at line 208 of file stk_memory_allocator.h.

209 : capacity(capacity_), allocated(0U), peak_allocated(0U), allocate_count(0U), free_count(0U),
210 alloc_fail_count(0U), min_ever_free(capacity_)
211 {}
volatile size_t allocated
Number of bytes currently allocated (dynamic value).
volatile size_t allocate_count
Number of successful allocations with Allocate().
size_t capacity
Total capacity of the memory pool in bytes.
volatile size_t free_count
Number of successful frees with Free().
volatile size_t min_ever_free
Minimum free bytes recorded since system start (watermark).
volatile size_t alloc_fail_count
Number of allocation requests that could not be satisfied.
volatile size_t peak_allocated
Maximum number of bytes that were allocated at the same time (high watermark).

References alloc_fail_count, allocate_count, allocated, capacity, free_count, min_ever_free, and peak_allocated.

Member Function Documentation

◆ GetAvailable()

size_t stk::memory::MemoryAllocator::Stats::GetAvailable ( ) const
inline

Get number of bytes currently available for allocation.

Returns
Available bytes.

Definition at line 245 of file stk_memory_allocator.h.

246 {
247 const size_t used = allocated;
248 return ((used < capacity) ? (capacity - used) : 0U);
249 }

References allocated, and capacity.

Referenced by RecordAllocate(), vPortGetHeapStats(), and xPortGetFreeHeapSize().

Here is the caller graph for this function:

◆ GetCapacity()

size_t stk::memory::MemoryAllocator::Stats::GetCapacity ( ) const
inline

Get total capacity of the memory pool.

Returns
Capacity in bytes.

Definition at line 240 of file stk_memory_allocator.h.

240{ return capacity; }

References capacity.

◆ RecordAllocate()

void stk::memory::MemoryAllocator::Stats::RecordAllocate ( size_t size)
inline

Record successful allocation.

Parameters
[in]sizeSize of allocated memory chunk.

Definition at line 254 of file stk_memory_allocator.h.

255 {
256 const size_t used = (allocated + size);
257
258 allocated = used;
260
261 if (used > peak_allocated)
262 {
263 peak_allocated = used;
264 }
265
266 const size_t avail = GetAvailable();
267 if (avail < min_ever_free)
268 {
269 min_ever_free = avail;
270 }
271 }
size_t GetAvailable() const
Get number of bytes currently available for allocation.

References allocate_count, allocated, GetAvailable(), min_ever_free, and peak_allocated.

Here is the call graph for this function:

◆ RecordAllocFail()

void stk::memory::MemoryAllocator::Stats::RecordAllocFail ( )
inline

Record failed allocation request.

Definition at line 288 of file stk_memory_allocator.h.

289 {
291 }

References alloc_fail_count.

◆ RecordFree()

void stk::memory::MemoryAllocator::Stats::RecordFree ( size_t size)
inline

Record successful deallocation.

Parameters
[in]sizeSize of freed memory chunk.

Definition at line 276 of file stk_memory_allocator.h.

277 {
278 const size_t used = allocated;
279
280 STK_ASSERT(used >= size);
281
282 allocated = ((used >= size) ? (used - size) : 0U);
283 free_count = (free_count + 1U);
284 }
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:532

References allocated, free_count, and STK_ASSERT.

◆ Reset()

void stk::memory::MemoryAllocator::Stats::Reset ( size_t capacity_)
inline

Restart the statistics for a pool of the given capacity.

Clears all counters and watermarks. Used by pools that learn their real capacity only after aligning/trimming their storage.

Parameters
[in]capacity_Total capacity in bytes.

Definition at line 226 of file stk_memory_allocator.h.

227 {
228 capacity = capacity_;
229 allocated = 0U;
230 peak_allocated = 0U;
231 allocate_count = 0U;
232 free_count = 0U;
233 alloc_fail_count = 0U;
234 min_ever_free = capacity_;
235 }

References alloc_fail_count, allocate_count, allocated, capacity, free_count, min_ever_free, and peak_allocated.

Member Data Documentation

◆ alloc_fail_count

volatile size_t stk::memory::MemoryAllocator::Stats::alloc_fail_count

Number of allocation requests that could not be satisfied.

Definition at line 218 of file stk_memory_allocator.h.

Referenced by RecordAllocFail(), Reset(), and Stats().

◆ allocate_count

volatile size_t stk::memory::MemoryAllocator::Stats::allocate_count

Number of successful allocations with Allocate().

Definition at line 216 of file stk_memory_allocator.h.

Referenced by RecordAllocate(), Reset(), Stats(), and vPortGetHeapStats().

◆ allocated

volatile size_t stk::memory::MemoryAllocator::Stats::allocated

Number of bytes currently allocated (dynamic value).

Definition at line 214 of file stk_memory_allocator.h.

Referenced by GetAvailable(), RecordAllocate(), RecordFree(), Reset(), and Stats().

◆ capacity

size_t stk::memory::MemoryAllocator::Stats::capacity

Total capacity of the memory pool in bytes.

Definition at line 213 of file stk_memory_allocator.h.

Referenced by GetAvailable(), GetCapacity(), Reset(), and Stats().

◆ free_count

volatile size_t stk::memory::MemoryAllocator::Stats::free_count

Number of successful frees with Free().

Definition at line 217 of file stk_memory_allocator.h.

Referenced by RecordFree(), Reset(), Stats(), and vPortGetHeapStats().

◆ min_ever_free

volatile size_t stk::memory::MemoryAllocator::Stats::min_ever_free

Minimum free bytes recorded since system start (watermark).

Definition at line 219 of file stk_memory_allocator.h.

Referenced by RecordAllocate(), Reset(), Stats(), vPortGetHeapStats(), and xPortGetMinimumEverFreeHeapSize().

◆ peak_allocated

volatile size_t stk::memory::MemoryAllocator::Stats::peak_allocated

Maximum number of bytes that were allocated at the same time (high watermark).

Definition at line 215 of file stk_memory_allocator.h.

Referenced by RecordAllocate(), Reset(), and Stats().


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