3 ms·
Not all microcontrollers have too little RAM for a heap. Sure, putting a heap on your little Atmega182p is foolish, but some have 1 megabyte of RAM or more. For
by colejohnson66 5y ago
Not all microcontrollers have too little RAM for a heap. Sure, putting a heap on your little Atmega182p is foolish, but some have 1 megabyte of RAM or more. For example, the Teensy 4.1 is a beast, relatively speaking.[0]
Not disagreeing with you. Just pointing out that not all microcontrollers are puny. Check your IC specs before deciding things.
[0]: https://www.pjrc.com/store/teensy41.html https://www.pjrc.com/store/teensy41.html
- dropje 5y agoIn 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.
- colejohnson66 5y agoWhy 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.
- Dylan16807 5y agoIt'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.