Hacker News new | ask | show | jobs
by dropje 1711 days ago
In the context of microcontrollers I think the issue with using a heap is not per se that you do not have enough memory, but more that your memory usage becomes unpredictable or very hard to make any guarantees about.
1 comments

Why would the heap make memory usage unpredictable? How’s it any different than the stack? For example, if I stack allocate 1000 bytes, leaving the function frees those bytes (by destroying the frame). If I allocate those 1000 bytes on the heap instead and make sure to free() it, there’s no change to memory usage.
It's easier to figure out what calls what and the maximum stack depth of some or all of the program. Trying to track maximum usage based on allocations is a lot harder, especially when you have to deal with fragmentation.