Skip to content

Dmod_MallocTagged: memory of a kind, else the default memory - #332

Merged
JohnAmadis merged 1 commit into
developfrom
feature/malloc-tagged
Oct 17, 2026
Merged

JohnAmadis merged 1 commit into
developfrom
feature/malloc-tagged

Conversation

@JaxCalder

Copy link
Copy Markdown
Contributor

What

A module can ask for memory of a kind:

void* state = Dmod_MallocTagged("fast", sizeof(state_t));   /* freed with Dmod_Free() */
  • Tags - kinds of memory, preferred first, separated by commas: "fast" (internal RAM worth giving to what is worked on all the time), "dma" (memory DMA reaches without cache maintenance), ... - as the system tags its heaps;
  • a kind the system does not have, or one without room: the next one, at last what Dmod_MallocEx() gives;
  • Dmod_MallocTaggedEx(Tags, Size, ModuleName) is the builtin; its default (weak) implementation is Dmod_MallocEx() - on the host, or a system without heaps of kinds, a module asking for a kind still works.

dmheap implements it on a device: a heap's name becomes the list of its tags (choco-technologies/dmheap PR), dmod-boot tags its heaps.

Why

On the STM32F746G Discovery everything a module allocates lands in the SDRAM (the newest default heap), behind a 4 kB data cache. dmmp3's decoder state (23 kB, worked on for every frame) there took 70 % of the CPU to decode an MP3; in the DTCM 15 % - carhmi-demo's view went from a few frames a second to 25. A module had no way to ask for internal memory without depending on dmheap - which exists only in the firmware, so the module would not load on the host.

Tests

tests_dmod_malloc_tagged: without heaps of kinds, memory of any kind (and none, NULL, "") is the default memory.

🤖 Generated with Claude Code

Tags - kinds of memory, preferred first, separated by commas ("fast",
"dma", ...) - as the system tags its heaps (dmheap: a heap's name is the
list of its tags). A kind the system does not have, or one without room:
the next one, at last Dmod_MallocEx()'s memory. The default implementation
is Dmod_MallocEx(), so a module asks for what it gains from and works
anywhere - on the host too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JohnAmadis
JohnAmadis self-requested a review October 17, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants