Are stack memory and heap memory allocated in different locations in memory? In class that’s how they taught us it works. Specifically in c++, when allocating memory on the heap, you need to keep track of it with pointers, cause if you lose where it is, it could be anywhere in the computer so the compiler doesn’t know where to deallocate it. At least that’s how I interpreted it.
But a student in my class, who’s a really good programmer and knows a lot about programming, said that heap and stack can be stored next to each other. And what you’re doing when you allocate memory on the heap, is your telling the compiler to keep this memory indefinitely. Vs normal stack memory tells the compiler to only keep this memory allocated for as long as the program is running?
So which is it? A mixture of both? Neither? A lot more complicated than a simple analogy? Thank you.
I was expecting it to the two different types of memory to be in different locations in the computer. But now I’m not sure.