Hello everyone,
I have a project which needs to work in real time and can't
afford to hang or undergo any access violation issues during
its execution. I typically use malloc/free extensively!!! Then, I
stumbled on the first few paragraphs of the following article:
(see around the middle of the article under
"Memory Fragmentation")
http://www.design-reuse.com/articles/25090/dynamic-memory-allocation-fragmentation-c.htmlNow I am worried! If using malloc in MCUs such as pic32 can cause
memory fragmentation, which may cause our programs to hang, then
why should we ever use malloc for embedded systems...
more over, why do compilers for MCUs even offer the possibility
of memory allocation if using malloc can represent such a risk?
Kowing this, really discourages me as it leads me to wonder why did I
bother learning how to malloc arrays, structures, arrays of structures
and arrays of pointers for??
My question is, should we or not use malloc in MCUs ?
Also, if one allocates say 50k in ram, would it be safe
to malloc 3 or four mallocs of 5k each? I don't see how
any problems can arise with this sort of leeway!
thanks