3 ms·
> Not saying it's good practice to be using malloc() in this environment but you'll get away with it. Actually, for the sake of keeping code modular and portab
by kosma 10y ago
> Not saying it's good practice to be using malloc() in this environment but you'll get away with it.
Actually, for the sake of keeping code modular and portable, it's fine to malloc() once on boot and never free(). It's the "dynamic" part of memory management that's dangerous on MCUs, especially on those without an MMU (as fragmentation gets in the way very often and you can't really reason about memory usage anymore).
- wyager 10y agoIf you're using malloc on boot only, you can almost always replace that with a static data declaration, which usually gets put in the same space the heap would otherwise use. It's better because the compiler can drop malloc, saving you some flash space, and static analysis tools can see how much RAM you're using (and if something is clearly going to blow up).