+ 2

Heap and stack memory

Hi I have couple of questions on memory from C++ stand point. 1. We have stack overflow when infinite recursion is called. Is it called stack corruption as well or it is a different concept all together? 2. What is heap corruption? If I get all the memory address and set it as null , is this called heap corruption? If not, what is heap corruption? 3. Also heap overflow concept is there or not? If yes , how? 4. Each C++ program has its own stack. Is this true? Can anyone corrupt entire machine's stack from a single c++ program? 5. Each C++ program don't have its own heap. It's common across the system. Is this true? Can anyone corrupt entire machine's heap from a single c++ program?

8th Aug 2021, 8:02 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Réponses
+ 2
Ketan Lalcheta looks like you are confused between terms here Memory corruption happens when a program tries to acess (read/writes) memory location that it is not allowed to acess. ( For example, trying to acess a freed memory location ). Memory leak happens when program doesn't deallocate the allocated memory, which leads to program taking much more resources than it should have causing performance issues and even crashes in extreme cases.
9th Aug 2021, 2:57 AM
Arsenic
Arsenic - avatar
0
Thanks Jay Matthews ...it's useful This cause another question as well in my mind... Is memory leak and corruption is same for heap?
8th Aug 2021, 8:59 AM
Ketan Lalcheta
Ketan Lalcheta - avatar