- malloc is slow and allocates on the heap. Good for large objects or objects that need to get their lifetime extended beyond the function where they are created.
- static allocation is on the stack. Allocation baked in by compiler so essentially free time-wise. Good for small objects. Risk of SO otherwise.
In a nutshell, I stand by these rules to decide how to allocate blocks of memory.
I work on embedded devices where time and space constraints are exacerbated, and I cringe whenever I see VLA as I don't know what the underlying implementation will do and whether it will make the right choice. So my rule of thumb is to stay away from them. Are there situations where it is preferable to use VLA rather than the classical malloc or static allocations, especially with respect to the embedded space?