picofuse

Data Structures | Typedefs | Functions
Memory
Collaboration diagram for Memory:

Data Structures

struct  hw_memory_usage_t
 Snapshot of active memory use. More...
 

Typedefs

typedef struct hw_memory_usage_t hw_memory_usage_t
 Snapshot of active memory use. More...
 

Functions

bool hw_memory_get_usage (hw_memory_usage_t *usage)
 Obtain a memory usage snapshot for the current platform. More...
 

Detailed Description

Note
Only implemented on Pico. On every other platform, hw_memory_get_usage() still succeeds (returns true) but reports every field as zero - there's no real RAM/stack/flash accounting backend for a host OS, which already manages all of that itself.

Typedef Documentation

◆ hw_memory_usage_t

Snapshot of active memory use.

Unsupported regions are reported as zero. On Pico, RAM fields describe primary SRAM, where globals, static data, and the heap reside; stack fields describe the current core's separate scratch-SRAM stack.

Function Documentation

◆ hw_memory_get_usage()

bool hw_memory_get_usage ( hw_memory_usage_t usage)

Obtain a memory usage snapshot for the current platform.

On Pico, RAM capacity and free space come from linker and C allocator state. Heap usage is a high-water mark and freeing memory does not reduce it. Flash free space excludes the image's final partially occupied erase sector and any flash block region reserved by hw_block_flash_init().

Calculate percentages only when the corresponding total is nonzero:

double ram_free_percent = 100.0 * usage.ram_free_bytes /
usage.ram_total_bytes;
double stack_free_percent = 100.0 * usage.stack_free_bytes /
usage.stack_total_bytes;
double flash_free_percent = 100.0 * usage.flash_free_bytes /
usage.flash_total_bytes;

ram_free_percent describes primary SRAM available for heap growth. Stack capacity is separate scratch SRAM and has its own percentage.

Parameters
usageOutput snapshot. Must not be NULL.
Returns
true on success, false when usage is NULL.