What are the differences between stack and heap memory allocation in C++, and how do they impact performance?