Explain the difference between stack and heap memory allocation in C++ and how it impacts real-time execution.