Wow wow, if you are using a heap on really small embedded device you're gonna have a bad time any way.<p>Embedded engineering 101: statically allocate everything, and try not to push the stack too much. But you can not do this with JS :(
"I have worked with a few embedded SDKs (by Microchip, Keil and Espressif), and all of them have a really dumb built-in implementation of the heap."<p>Many embedded systems allocate just once at startup and these "really dumb" implementations are completely sufficient. The vendors provide a fast, low-overhead solution by default and trust that developers can go find a more appropriate allocator if they need it for their application. Luckily we have many implementations to choose from!
Generally speaking, you should try really hard to avoid using the heap in any system that has no virtual memory support. Heap fragmentation will ultimately get your app.<p>The exception is in state machines where you know, in a deterministic way, what the memory layout should be at every given state, and then you can use heaps to get memory overlap between code pieces that operate exclusively of each other.
The allocator that comes with free rtos (I assume he's using it as he mentions pvPortMalloc) can be extended to support realloc efficiently without too much trouble so that it will resize if possible. For example <a href="https://github.com/hello/heap_6" rel="nofollow">https://github.com/hello/heap_6</a>
From 2010, very similar approach: <a href="http://www.asyndetic.com/2010/07/30/visualizing-the-heap-on-embedded-systems-part-ii/" rel="nofollow">http://www.asyndetic.com/2010/07/30/visualizing-the-heap-on-...</a>