esp32-heap-discipline

Solid

Memory-allocation discipline for AgentDeck ESP32 firmware (esp32/). Use whenever writing or reviewing firmware code that allocates — new / malloc / ps_malloc / heap_caps_alloc / std::vector / std::string / String / a buffer / a cache / anything held across a render loop. Covers the PSRAM-vs-no-PSRAM board split, the allocation decision order, fragmentation avoidance, the makeUniqueNoThrow / ScopedCleanup helpers, the PROTOCOL_MAX_MSG_BYTES JSON guard, and the heap diagnostics (logHeap / [PERF] freeblk).

AI & Automation 167 stars 29 forks Updated yesterday MIT

Install

View on GitHub

Quality Score: 86/100

Stars 20%
74
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# ESP32 Heap Discipline Memory rules for `esp32/` firmware. Adapted from crosspoint-reader's `heap-discipline` skill to AgentDeck's multi-board reality. This is the procedure you run while writing firmware and the gate before handing it back. ## The board split — know which world you're in AgentDeck firmware targets two memory regimes. Check the board macros first. - **PSRAM boards** — `BOARD_BOX_86`, `BOARD_IPS35`, `BOARD_AMOLED`, `BOARD_IPS10` (ESP32-S3 / -P4, 8–32MB PSRAM). Large canvases/caches go in PSRAM (`ps_malloc` / `MALLOC_CAP_SPIRAM`). **But** per-pixel / LVGL draw buffers and PPA rotation buffers must stay in **internal SRAM** (`MALLOC_CAP_INTERNAL`): PSRAM writes are ~30× slower, so a PSRAM draw buffer makes every widget render crawl (see the IPS10 rationale in `esp32/src/ui/display.cpp`). Plenty of total RAM here; the constraint is *write latency and internal-SRAM headroom*, not bytes. - **No-PSRAM boards** — `BOARD_TTGO` (classic ESP32, ~160KB heap), `BOARD_ESP32_C6_147` (single-core RISC-V), `BOARD_LED8X32` (TC001). This is crosspoint's world: every allocation matters and **fragmentation, not total usage, is what kills the device.** Free heap can read fine while the largest free block is too small for the next alloc. Optimize for not leaving holes. The canvas/buffer code already encodes this split (`renderer.cpp::init` uses static pre-allocated buffers on TTGO/C6 and `ps_malloc`+SRAM fallback elsewhere). Match the existing pattern; d...

Details

Author
puritysb
Repository
puritysb/AgentDeck
Created
5 months ago
Last Updated
yesterday
Language
C
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

Code & Development Solid

esp32-expert

This skill should be used when the user is writing, reviewing, debugging, or architecting C++ firmware for ESP32 and variants (ESP32-S2, S3, C3, C5, C6, H2, P4) using ESP-IDF or PlatformIO. Provides expert critique covering FreeRTOS task design, memory management (IRAM/DRAM/PSRAM), peripheral drivers (I2C/SPI/UART/GPIO), build systems (CMake/platformio.ini), power management, OTA updates, and embedded C++ best practices. Use when the user asks "review my ESP32 code", "fix FreeRTOS crash", "optimize memory usage", "debug I2C issue", "set up PlatformIO project", "review my CMakeLists", "search datasheet for this chip", "why is my task crashing", "configure deep sleep", or "help with ESP-IDF component structure".

11 Updated today
johnkozaris
Code & Development Listed

esp32-expert

This skill should be used when the user is writing, reviewing, debugging, or architecting C++ firmware for ESP32 and variants (ESP32-S2, S3, C3, C6, H2, P4) using ESP-IDF or PlatformIO. Provides expert critique covering FreeRTOS task design, memory management (IRAM/DRAM/PSRAM), peripheral drivers (I2C/SPI/UART/GPIO), build systems (CMake/platformio.ini), power management, OTA updates, and embedded C++ best practices. Use when the user asks "review my ESP32 code", "fix FreeRTOS crash", "optimize memory usage", "debug I2C issue", "set up PlatformIO project", "review my CMakeLists", "search datasheet for this chip", "why is my task crashing", "configure deep sleep", or "help with ESP-IDF component structure".

4 Updated yesterday
mathisk2095
AI & Automation Listed

memory-contexts

Allocate memory in PostgreSQL backend C — pick the right MemoryContext and use palloc / palloc0 / pstrdup / psprintf correctly. Covers CurrentMemoryContext / TopMemoryContext / per-query / per-tuple / ExecutorState context choice, MemoryContextSwitchTo discipline, the OOM-throws-ereport contract (no NULL checks), pfree vs MemoryContextReset vs MemoryContextDelete, the AllocSet vs Slab vs Generation vs Bump context-type cheat sheet, and leak-scoping in long-running backends. Use whenever a PG patch or extension calls palloc / palloc0 / MemoryContextAlloc, creates or switches a MemoryContext, picks AllocSet vs Slab vs Generation vs Bump, or debugs a context-shaped leak. Skip for plain malloc / free / jemalloc / mimalloc / tcmalloc, JVM / Go / .NET GC tuning, Rust Box / Rc / Arc / lifetimes, shared_buffers / work_mem production tuning, valgrind / heaptrack on non-PG programs, and C++ smart pointers.

0 Updated 5 days ago
matejformanek