Explain the difference between stack and heap allocation, and how dynamic memory allocation impacts real-time loop performance.