memory-mgmt-patterns

A reference guide to managing memory in embedded firmware without unpredictable allocation or fragmentation. It covers fixed memory reserved before the program runs.

In plain words
What is it for?
Use it when creating FreeRTOS tasks, queues, semaphores, and memory pools with fixed storage.
Why use it?
It helps keep memory use predictable and avoids failures caused by repeated dynamic allocation on small devices.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/hermeticormus/libreembed-claude-code/memory-mgmt-patterns
Any agent
npx skills add HermeticOrmus/LibreEmbed-Claude-Code --skill memory-mgmt-patterns
Clone the repo
git clone --depth 1 https://github.com/HermeticOrmus/LibreEmbed-Claude-Code

Made for: Claude Code, Codex.

Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,354 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01354
Opus 5 $0.00000 $0.00677
Sonnet 5 $0.00000 $0.00271
Haiku 4.5 $0.00000 $0.00135

Measured 3d ago against content hash be141cf2e0b3, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

memory-mgmt-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/memory-management/skills/memory-mgmt-patterns/SKILL.md · 187 lines

How it starts

The opening of the file, as written. The whole thing — 187 lines — stays where its author put it; the contents beside it link to each section on GitHub.

memory-mgmt-patterns

Knowledge Base

Embedded memory management patterns for deterministic, fragmentation-free firmware.


Pattern 1: Static FreeRTOS Objects

Avoid dynamic allocation for RTOS objects. All objects pre-allocated at compile time.

/* Static task */
static StackType_t  s_sensor_stack[256];
static StaticTask_t s_sensor_tcb;
static TaskHandle_t s_sensor_handle;

/* Static queue: 8 messages of 16 bytes each */
static uint8_t          s_queue_storage[8 * 16];
static StaticQueue_t    s_queue_struct;
static QueueHandle_t    s_queue;

/* Static semaphore */
static StaticSemaphore_t s_sem_struct;
static SemaphoreHandle_t s_sem;

void rtos_objects_create(void)
{
    s_sensor_handle = xTaskCreateStatic(
        sensor_task, "sensor",
        256U, NULL, TASK_PRIO_SENSOR,
        s_sensor_stack, &s_sensor_tcb);
    configASSERT(s_sensor_handle != NULL);

    s_queue = xQueueCreateStatic(8, 16, s_queue_storage, &s_queue_struct);
    configASSERT(s_queue != NULL);

    s_sem = xSemaphoreCreateBinaryStatic(&s_sem_struct);
    configASSERT(s_sem != NULL);
}

Required in FreeRTOSConfig.h: configSUPPORT_STATIC_ALLOCATION 1.


Pattern 2: Memory Pool for Variable-Frequency Messages

When messages arrive at variable rate, a pool prevents heap fragmentation:

/* Message pool: 32 messages, 128 bytes each */
typedef struct {
    uint8_t  data[120];
    uint8_t  len;
    uint8_t  type;
    uint16_t seq;
} msg_t;

#define MSG_POOL_SIZE 32U
static msg_t      s_msg_pool[MSG_POOL_SIZE];
static uint32_t   s_pool_used_mask = 0U;  /* Bitmask: bit N = msg N is in use */

msg_t *msg_alloc(void)
{
    taskENTER_CRITICAL();
    for (uint32_t i = 0; i < MSG_POOL_SIZE; i++) {
        if (!(s_pool_used_mask & (1U << i))) {
            s_pool_used_mask |= (1U << i);
            taskEXIT_CRITICAL();
            return &s_msg_pool[i];
        }
    }
    taskEXIT_CRITICAL();
    return NULL;  /* Pool exhausted: caller must handle */
}

void msg_free(msg_t *m)
{
    uint32_t idx = (uint32_t)(m - s_msg_pool);
    configASSERT(idx < MSG_POOL_SIZE);
    taskENTER_CRITICAL();
    s_pool_used_mask &= ~(1U << idx);
    taskEXIT_CRITICAL();
}

Read the full file on GitHub · 187 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 187 lines · 0 tokens per session scan A be141cf2e0b3

Subscribe to this mod's changes

memory-mgmt-patterns is a skill published in the GitHub repository HermeticOrmus/LibreEmbed-Claude-Code (44 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,354 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

hardware-iot-bus

Low-level I2C and SPI bus peripheral control for embedded Linux boards (Orange Pi, Raspberry Pi, RISC-V).

AbdullahMalik17/malikclaw · 31 tokens

aether-iot-query

Use this skill when the user asks about a live AetherEdge runtime: channels, points, real-time values, history, alarms, rules, models, instances, routing, SHM health, service health, or system status. Use aether CLI commands to answer — do NOT inspect source code, local database files, or config YAMLs to answer…

EvanL1/AetherEdge · 82 tokens

aether-iot

Build, integrate, diagnose, or generate applications for the AetherEdge AI-native edge kernel. Use for AetherEdge onboarding, SDK compositions, device and topology clients, read-only operations UIs, MCP integration, Domain Packs, or governed IoT commands where live-state authority and physical-device safety must be…

EvanL1/AetherEdge · 68 tokens

avr-bare-metal-embedded

Curated Knowledge API for AI Agents — 68 MCP tools, 200+ skill packs, 46K chunks, semantic search over 670K vectors, 5-layer validation pipeline. Works with Claude Code, Cursor, Cline, Windsurf.

MidOSresearch/midos · 6 tokens

smart-product-dev

End-to-end IoT product development orchestration for TuyaOpen projects. Guides from requirements gathering → Tuya Platform product/DP creation → complete embedded firmware generation. State-machine: detects project state and picks up from wherever development currently stands.

tuya/tuyaopen-ide-manifests · 52 tokens

edge-iot

Edge computing, IoT protocols, and embedded systems integration.

miles990/claude-software-skills · 15 tokens