What are the primary differences between stack and heap memory allocation, and how do they impact real-time system performance?