" Lock the Malloc"
Koustubh Tilak
CTO| Leadership | Autonomous driving | ISO 26262 | Cybersecurity | Vehicle Dynamics Expert | ADAS | AI/ML | Safety Critical Software | RADAR | UWB | MBD-HIL | Owner - Joshi Sweets Baner | keynote speaker
Malloc is a popular function because it offers several advantages like optimized usage of RAM ( unlike array which is highly non optimal) and ease of building generic framework to implement things like decision trees ( where input length is variable) , DNNs and CNNs with varying number of input and output nodes , varying number of hidden layers etc.
Unfortunately, one of the most dangerous constructs to use in any embedded program is malloc, because it could potentially lead to memory leaks, dangling pointers, memory corruption, program
The key question to answer is "can we still use malloc and remain safe"
One of the ways to safely use #malloc without compromising benefits offered is : "Partitioned memory based upper bounded, dynamic maximum size allocation to elements requiring malloc"
1. First and foremost, all the elements using malloc must be able to allocate memory from a separate partition typically called as heap.
2. Next is fixed maximum memory size allocation limit statically decided and allocated to each element requiring dynamic memory access
3. Last but not the least, the available limit statically decided can be updated dynamically after invocation of every call to #free
If these rules are not followed the program is sitting on a time bomb which could explode any time, anywhere !