cpp-memory-opt

Optimize ESP32 pool-controller firmware memory usage and reduce heap fragmentation.

25|7|Updated Mar 4, 2019
One-click install
npx skills add https://github.com/smart-swimmingpool/pool-controller --skill cpp-memory-opt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp-memory-opt
Source: https://github.com/smart-swimmingpool/pool-controller/tree/main/.opencode/skills/cpp-memory-opt
Command: npx skills add https://github.com/smart-swimmingpool/pool-controller --skill cpp-memory-opt

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Memory optimization for ESP32-based pool-controller firmware to reduce heap fragmentation and minimize dynamic allocations.

Core Features & Use Cases

  • Eliminate risky dynamic allocations in hot paths (e.g., String usage in loops)
  • Size and manage ArduinoJson buffers safely (StaticJsonDocument sizing)
  • Prefer function-local buffers and proper NVS usage for robust 24/7 operation
  • Improve stability for long-running deployments and memory-constrained devices

Quick Start

Run the memory optimization routine on the ESP32 pool-controller project to reduce heap fragmentation and RAM usage.

Frequently Asked Questions about cpp-memory-opt

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce ESP32 heap fragmentation in a long-running embedded deployment?

Reduce ESP32 heap fragmentation by eliminating risky dynamic allocations in hot paths, preferring function-local buffers, and sizing StaticJsonDocument safely to stabilize long-running embedded deployments and prevent memory pressure reboots.

What is the best way to size ArduinoJson buffers on ESP32 without causing memory issues?

Size ArduinoJson buffers safely by using StaticJsonDocument with appropriately calculated static allocation sizes, avoiding oversized dynamic heap reservations that contribute to memory fragmentation on constrained ESP32 devices.

Why does my ESP32 pool-controller firmware reboot during continuous 24/7 operation?

ESP32 firmware reboots during 24/7 operation typically occur because memory pressure from heap fragmentation and dangerous string allocations in loops forces the system to reset to recover available RAM.

Can I use String objects in ESP32 loops without causing memory fragmentation?

Using String objects in ESP32 loops causes heap fragmentation because each operation triggers dynamic reallocation; replacing them with static allocation patterns and function-local buffers prevents this degradation.

Does ESP32 NVS usage help reduce heap fragmentation for persistent data?

ESP32 NVS usage reduces heap fragmentation by moving persistent data storage out of RAM, utilizing non-volatile storage instead of maintaining dynamic memory structures during long-running embedded deployments.

When should I choose stack vs heap allocation for ArduinoJson on the ESP32?

Choose stack allocation for small, short-lived ArduinoJson buffers to avoid heap fragmentation, and reserve heap allocation for larger documents only when stack limits are exceeded, ensuring stable 24/7 memory behavior.