When converting dynamic memory allocations (run-time) to static allocations (compilation time), two problems arise. First, the compiler obviously needs to know how much memory is allocated at compile time. In the above example, it looks like any decoder β sync points are a constant size, so this should not be a problem. If you allocated memory for a byte array for a variable-length data sequence, you would run into a problem. You need to either select enough for the maximum possible data length, or break the data into pieces, or ... I hope you get this idea.
Another problem is heap and stack. All dynamic memory allocations come from the heap. Non-global distributions of static memory come from the stack, and the stacks can be quite small in embedded environments. This means that if the memory allocation is medium-term, you probably need to make it global or βstaticβ (static variables with local scope also go out of the heap) to avoid, even if the variable would not otherwise be global.
Hope this makes sense.
source share